diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-07-01 13:24:05 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-07-01 13:24:05 +0000 |
commit | cf1b401909b5e54edfd80656b1a18eaa31f9f6f1 (patch) | |
tree | edb0ffff2a43d84ba9b4c862b394cfeeebb36ddc /test/SemaCXX/constant-expression-cxx11.cpp | |
parent | ef915aab0ac566c55bfb0d7a9f6635bb5d94d4af (diff) | |
download | src-test2-cf1b401909b5e54edfd80656b1a18eaa31f9f6f1.tar.gz src-test2-cf1b401909b5e54edfd80656b1a18eaa31f9f6f1.zip |
Notes
Diffstat (limited to 'test/SemaCXX/constant-expression-cxx11.cpp')
-rw-r--r-- | test/SemaCXX/constant-expression-cxx11.cpp | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/test/SemaCXX/constant-expression-cxx11.cpp b/test/SemaCXX/constant-expression-cxx11.cpp index 4abbc8e92847..3fda2d0a7fd0 100644 --- a/test/SemaCXX/constant-expression-cxx11.cpp +++ b/test/SemaCXX/constant-expression-cxx11.cpp @@ -608,7 +608,7 @@ namespace DependentValues { struct I { int n; typedef I V[10]; }; I::V x, y; -int g(); +int g(); // expected-note {{declared here}} template<bool B, typename T> struct S : T { int k; void f() { @@ -616,13 +616,23 @@ template<bool B, typename T> struct S : T { I &i = cells[k]; switch (i.n) {} - // FIXME: We should be able to diagnose this. - constexpr int n = g(); + constexpr int n = g(); // expected-error {{must be initialized by a constant expression}} expected-note {{non-constexpr function 'g'}} constexpr int m = this->g(); // ok, could be constexpr } }; +extern const int n; +template<typename T> void f() { + // This is ill-formed, because a hypothetical instantiation at the point of + // template definition would be ill-formed due to a construct that does not + // depend on a template parameter. + constexpr int k = n; // expected-error {{must be initialized by a constant expression}} +} +// It doesn't matter that the instantiation could later become valid: +constexpr int n = 4; +template void f<int>(); + } namespace Class { |