[LLVMbugs] [Bug 13492] New: Explicitly defaulted constructors are not constexprs, yet are treated as such for constant creation

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Jul 31 13:33:56 PDT 2012


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

             Bug #: 13492
           Summary: Explicitly defaulted constructors are not constexprs,
                    yet are treated as such for constant creation
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: aaron at aaronballman.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified


The following snippets should provide the same error, but don't in clang (ToT):

struct A {
};

struct B {
  B() = default;
};

struct C {
  C() {}  // Automatically gains constexpr since it qualifies
};

int main( void ) {
  const A a;  // Error
  const B b;  // Error
  const C c;  // OK
  return 0;
}

This is because:

dcl.fct.def.default/2:
An explicitly-defaulted function may be declared constexpr only if it would
have been implicitly declared as constexpr

and

class.ctor/5:
An implicitly-declared default constructor is an inline public member of its
class. 

class.ctor/6:
If that user-written default constructor would satisfy the requirements of a
constexpr constructor, the implicitly-defined default constructor is constexpr.

So only user-written default constructors gain automatic constexpr magic.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list