error: destructor reference must be called immediately with '()' (Why dtor is an exception?)

Hi cfe-dev,

After moving to LLVM/Clang 3.5 I have noticed some failures, seems to be coming from the following (5 years old) commit: If a destructor is referenced or a pseudo-destructor expression is · llvm-mirror/clang@a78c5c3 · GitHub

We started getting these kind of errors:

AnalysisDataFormatsTopObjects/a/xr.cc:915:2: error: destructor reference must be called immediately with '()'
(((::TtDilepEvtSolution*)o)->::TtDilepEvtSolution::~TtDilepEvtSolution)();
^
                                                    ()
AnalysisDataFormatsTopObjects/a/xr.cc:915:72: error: called object type 'void' is not a function or function pointer

Small example below. Why is that only after dtor you **require** next token to be '('? Yet it's fully fine to add as many extra parentheses in other cases (see Point::dump below).

Comment from commit: The only way a reference to a destructor can be used is to immediately call them. Since the next token is not a '(', produce a diagnostic and build the call now.

$ cat dtor.cc
#include <new>
#include <cstdlib>
#include <iostream>

class Point
{
  public:
    Point(int x, int y) : x(x), y(y) { std::cerr << "ctor " << x << " " << y << std::endl; }
    ~Point() { std::cerr << "dtor" << std::endl; }
    void dump() { std::cerr << "x: " << x << "; y:" << y << std::endl; }
  private:
    int x, y;
};

int main(int argc, char *argv)
{
  char *mem = (char *)malloc(100);
  Point *pt = new (mem) Point(10, 20);
  (pt->Point::dump)();
  (((pt->Point::dump)))();
  (pt->Point::~Point)();
}

$ clang++ dtor.cc
dtor.cc:20:4: error: destructor reference must be called immediately with '()'
  (pt->Point::~Point)();
   ^
               ()
dtor.cc:20:22: error: called object type 'void' is not a function or function pointer
  (pt->Point::~Point)();
  ~~~~~~~~~~~~~~~~~~~^
2 errors generated.

david