llvm-project/clang/test/SemaCXX/cxx1y-constexpr-not-const.cpp
Nico Weber 71e377d6ee If a function decl cannot be merged, mark it as invalid.
Clang currently crashes on

    class C {
      C() = default;
      C() = delete;
    };

My cunning plan for fixing this was to change the `if (!FnD)` in
Parser::ParseCXXInlineMethodDef() to `if (!FnD || FnD->isInvalidDecl)` – but
alas, the second constructor decl wasn't marked as invalid.  This lets
Sema::MergeFunctionDecl() return true on function redeclarations, which leads
to them being marked invalid.

This also improves error messages when functions are redeclared.

llvm-svn: 226365
2015-01-17 02:33:17 +00:00

17 lines
488 B
C++

// RUN: %clang_cc1 -std=c++11 %s -verify
// RUN: %clang_cc1 -std=c++1y %s -verify -DCXX1Y
struct X {
constexpr int f(); // @5
int f(); // @6
};
#ifdef CXX1Y
// FIXME: Detect this situation and provide a better recovery.
// expected-error@6 {{class member cannot be redeclared}}
// expected-note@5 {{previous}}
#else
// expected-warning@5 {{'constexpr' non-static member function will not be implicitly 'const' in C++14; add 'const' to avoid a change in behavior}}
#endif