简体   繁体   中英

Befriend default constructor: clang produces parse error while gcc did not

I encountered a confusing issue. For following snippet:

class A { };
class E
{
    friend A::A() throw();
};

I used Clang 6 to compile this code example and got "error: non-constexpr declaration of 'A' follows constexpr declaration". I also tried clang 4.0, clang 5.0 and gcc 5.4 and there were no this kind of error. Is this a bug in Clang6?

From class.ctor#7

the implicitly-defined default constructor is constexpr

Since there is no user-declared constructor for class A , a non-explicit constructor having no parameters is implicitly declared as defaulted

However,

friend A::A() throw();

You explicitly declare A::A() which doesn't match the implicitly-declared constructor (which is a constexpr constructor ).

Specifically:

either its function-body shall be = default, or the compound-statement of its function-body shall satisfy the requirements for a function-body of a constexpr function;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM