[cfe-dev] Problem with new C++17 noexcept rules

Pavel A. Lebedev via cfe-dev cfe-dev at lists.llvm.org
Sat Oct 29 08:50:18 PDT 2016


Hi.

Since r284549 'DR1330: instantiate exception-specifications when "needed"'
clang rejects the following:

$ cat d.cpp

struct S
{
    ~S();
    void f(const S& s = S());
};
S::~S() {}

$ clang++ -std=c++1z -fno-exceptions -fsyntax-only d.cpp

d.cpp:6:4: error: conflicting types for '~S'
S::~S() {}
   ^
d.cpp:3:5: note: previous declaration is here
    ~S();
    ^
1 error generated.

The error message is confusing (can it be improved?), but it seems
that clang considers the definition of destructor implicitly
noexcept(false),
unlike declaration, since adding explicit 'noexcept' to the definition
makes this compile again.
As expected, this example compiles without error for C++03/11/14,
since the commit in question is tweaking C++17-only rules.
Also, clang accepts it if -fno-exceptions is NOT specified, so this looks
like a bug to me.
This is the minimal test case I was able to produce - this error only
triggers for out-of-class destructor definitions when the class tries
to construct its own instances in member function default arguments.
This example was reduced from Qt, which breaks due to this pretty much
completely
and uses a combination of -std=c++1z and -fno-exceptions in default
configuration
when supported.

--- 
Pavel A. Lebedev




More information about the cfe-dev mailing list