diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2017-01-07 00:48:55 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2017-01-07 00:48:55 +0000 |
commit | d6a150829b04a63bdcc9bafe4fb7faa0e96a9df5 (patch) | |
tree | 005efe470ff275402614d3bbda5bb9036f67c11f /clang/test/SemaCXX/implicit-exception-spec.cpp | |
parent | 598861f661d90a87a4c6bec230b00386fa962da5 (diff) | |
download | bcm5719-llvm-d6a150829b04a63bdcc9bafe4fb7faa0e96a9df5.tar.gz bcm5719-llvm-d6a150829b04a63bdcc9bafe4fb7faa0e96a9df5.zip |
PR23135: Don't instantiate constexpr functions referenced in unevaluated operands where possible.
This implements something like the current direction of DR1581: we use a narrow
syntactic check to determine the set of places where a constant expression
could be evaluated, and only instantiate a constexpr function or variable if
it's referenced in one of those contexts, or is odr-used.
It's not yet clear whether this is the right set of syntactic locations; we
currently consider all contexts within templates that would result in odr-uses
after instantiation, and contexts within list-initialization (narrowing
conversions take another victim...), as requiring instantiation. We could in
principle restrict the former cases more (only const integral / reference
variable initializers, and contexts in which a constant expression is required,
perhaps). However, this is sufficient to allow us to accept libstdc++ code,
which relies on GCC's behavior (which appears to be somewhat similar to this
approach).
llvm-svn: 291318
Diffstat (limited to 'clang/test/SemaCXX/implicit-exception-spec.cpp')
-rw-r--r-- | clang/test/SemaCXX/implicit-exception-spec.cpp | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/clang/test/SemaCXX/implicit-exception-spec.cpp b/clang/test/SemaCXX/implicit-exception-spec.cpp index 12871b8ce70..fc86d1810ba 100644 --- a/clang/test/SemaCXX/implicit-exception-spec.cpp +++ b/clang/test/SemaCXX/implicit-exception-spec.cpp @@ -16,34 +16,32 @@ namespace InClassInitializers { // Noexcept::Noexcept is not declared constexpr, therefore noexcept(Noexcept()) // is false. bool ThrowSomething() noexcept(false); - struct ConstExpr { // expected-error {{default member initializer for 'b' needed}} - bool b = noexcept(ConstExpr()) && ThrowSomething(); // expected-note {{declared here}} - // expected-note@-1 {{implicit default constructor for 'InClassInitializers::ConstExpr' first required here}} + struct ConstExpr { + bool b = // expected-note {{declared here}} + noexcept(ConstExpr()) && ThrowSomething(); // expected-error {{default member initializer for 'b' needed}} }; // Much more obviously broken: we can't parse the initializer without already // knowing whether it produces a noexcept expression. - struct TemplateArg { // expected-error {{default member initializer for 'n' needed}} - int n = ExceptionIf<noexcept(TemplateArg())>::f(); // expected-note {{declared here}} - // expected-note@-1 {{implicit default constructor for 'InClassInitializers::TemplateArg' first required here}} + struct TemplateArg { + int n = // expected-note {{declared here}} + ExceptionIf<noexcept(TemplateArg())>::f(); // expected-error {{default member initializer for 'n' needed}} }; // And within a nested class. - struct Nested { // expected-note {{implicit default constructor for 'InClassInitializers::Nested::Inner' first required here}} - struct Inner { // expected-error {{default member initializer for 'n' needed}} + struct Nested { + struct Inner { int n = // expected-note {{declared here}} - ExceptionIf<noexcept(Nested())>::f(); // expected-note {{implicit default constructor for 'InClassInitializers::Nested' first required here}} - } inner; + ExceptionIf<noexcept(Nested())>::f(); + } inner; // expected-error {{default member initializer for 'n' needed}} }; - struct Nested2 { // expected-error {{implicit default constructor for 'InClassInitializers::Nested2' must explicitly initialize the member 'inner' which does not have a default constructor}} + struct Nested2 { struct Inner; - int n = Inner().n; // expected-note {{implicit default constructor for 'InClassInitializers::Nested2::Inner' first required here}} - struct Inner { // expected-error {{initializer for 'n' needed}} expected-note {{declared here}} - // expected-note@+1 {{declared here}} - int n = ExceptionIf<noexcept(Nested2())>::f(); - // expected-note@-1 {{implicit default constructor for 'InClassInitializers::Nested2' first required here}} - } inner; // expected-note {{member is declared here}} + int n = Inner().n; // expected-error {{initializer for 'n' needed}} + struct Inner { + int n = ExceptionIf<noexcept(Nested2())>::f(); // expected-note {{declared here}} + } inner; }; } |