[LLVMbugs] [Bug 21123] New: [3.5 Regression] error: destructor reference must be called immediately with '()'

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Oct 1 13:39:09 PDT 2014


http://llvm.org/bugs/show_bug.cgi?id=21123

            Bug ID: 21123
           Summary: [3.5 Regression] error: destructor reference must be
                    called immediately with '()'
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: david.abdurachmanov at gmail.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

http://lists.cs.uiuc.edu/pipermail/cfe-dev/2014-October/039371.html

After moving to LLVM/Clang 3.5 I have noticed some failures, seems to be coming
from the following (5 years old) commit:
https://github.com/llvm-mirror/clang/commit/a78c5c34fbd20fde02261c3f3e21933cd58fcc04

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.

>From IRC discussions:

davidlt: Could some comment on "error: destructor reference must be called
immediately with '()'" ?
o11c: davidlt: it means you can't type x.~X
davidlt: o11c: this means I cannot do this: (pt->Point::~Point)(); but all
other compilers allow it
o11c: davidlt: hm, that is a clang bug then
davidlt: o11c: yet I can do (((pt->Point::dump)))(); and add as much extra
parantheses as I want
K-ballo: davidlt: you can take a pointer to a member function, but not to a
constructor/destructor
davidlt: The for this check is 5 years old, but only started to work in 3.5
o11c: davidlt: parentheses are explicitly defined to have absolutely no effect
on the validity, so file a bug
o11c: (I was just reading this part of the standard, so I know what I'm talking
about)
K-ballo: o11c: (pt->Point::~Point) would be an expression, is that allowed as
an expression?
o11c: K-ballo: yes. the only constraint is that you must use a () immediately,
but the grouping is still fine
o11c: 5.2.4 says that pseudo-dtor calls are an expression; 5.1.1/6 gives the
rule about parentheses
o11c: references are from C++11
o11c: n3337 specifically
o11c: davidlt: possibly useful information to include in your bug report ^
K-ballo: o11c: what's the type of the expression pt->Point::~Point ?
o11c: K-ballo: The result shall only be used as the operand for the function
call operator (), and the result of such a call has type void
o11c: this is in 5.2.4
o11c: and 5.1.1/6 explicitly allows parentheses around any operand

$ 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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20141001/f6451cf2/attachment.html>


More information about the llvm-bugs mailing list