I am trying to implement something in clang and am investigating test cases. This test for example, starts with:
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
// Implicitly-defined default constructors are constexpr if the implicit
// definition would be.
struct NonConstexpr1 { // expected-note {{here}}
int a;
};
struct NonConstexpr2 { // expected-note {{here}}
NonConstexpr1 nl;
};
struct NonConstexpr2a : NonConstexpr1 { };
constexpr NonConstexpr1 nc1 = NonConstexpr1(); // ok, does not call constructor
constexpr NonConstexpr2 nc2 = NonConstexpr2(); // ok, does not call constructor
constexpr NonConstexpr2a nc2a = NonConstexpr2a(); // ok, does not call constructor
constexpr int nc2_a = NonConstexpr2().nl.a; // ok
constexpr int nc2a_a = NonConstexpr2a().a; // ok
struct Helper {
friend constexpr NonConstexpr1::NonConstexpr1(); // expected-error {{follows non-constexpr declaration}}
friend constexpr NonConstexpr2::NonConstexpr2(); // expected-error {{follows non-constexpr declaration}}
};
if I run that test through llvm-lit, it passes:
$ ./bin/llvm-lit -sv ../clang/test/CXX/special/class.ctor/p6-0x.cpp
llvm-lit: /home/brevzin/sandbox/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using clang: /home/brevzin/sandbox/llvm-project/build/bin/clang
llvm-lit: /home/brevzin/sandbox/llvm-project/llvm/utils/lit/lit/llvm/subst.py:126: note: Did not find cir-opt in /home/brevzin/sandbox/llvm-project/build/bin:/home/brevzin/sandbox/llvm-project/build/bin
Testing Time: 0.04s
Total Discovered Tests: 1
Passed: 1 (100.00%)
If I directly attempt to compile the part of this test though, I get a different error on those lines:
$ ./bin/clang++ -fsyntax-only -std=c++11 ex.cxx
ex.cxx:14:35: error: 'NonConstexpr1' is missing exception specification 'noexcept'
14 | friend constexpr NonConstexpr1::NonConstexpr1(); // expected-error {{follows non-constexpr declaration}}
| ^
| noexcept
ex.cxx:1:8: note: previous declaration is here
1 | struct NonConstexpr1 { // expected-note {{here}}
| ^
ex.cxx:15:35: error: 'NonConstexpr2' is missing exception specification 'noexcept'
15 | friend constexpr NonConstexpr2::NonConstexpr2(); // expected-error {{follows non-constexpr declaration}}
| ^
| noexcept
ex.cxx:4:8: note: previous declaration is here
4 | struct NonConstexpr2 { // expected-note {{here}}
| ^
2 errors generated.
And then there are other differences depending on how I test this file:
./bin/clang -cc1 -verify -std=c++11 ex.cxxpasses./bin/clang -cc1 -verify -std=c++11 ex.cxx -fcxx-exceptionsfails./bin/clang++ -Xclang -verify -std=c++11 ex.cxxfails
So I’m confused as to what’s actually going on. How is it that the test case passes?