summaryrefslogtreecommitdiffstats
path: root/test/FixIt
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2011-09-29 19:11:37 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2011-09-29 19:11:37 +0000
commitc6d990a767150b02337de1136fdb55ccf349f4d1 (patch)
treecb8db222a1cf25c4dde7a9e9f5ded3c92965b4ad /test/FixIt
parent97db7265ac1993e14e5877292e23d5ed2e9cf719 (diff)
constexpr: semantic checking for constexpr variables.
We had an extension which allowed const static class members of floating-point type to have in-class initializers, 'as a C++0x extension'. However, C++0x does not allow this. The extension has been kept, and extended to all literal types in C++0x mode (with a fixit to add the 'constexpr' specifier). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140801 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/FixIt')
-rw-r--r--test/FixIt/fixit-cxx0x.cpp44
1 files changed, 43 insertions, 1 deletions
diff --git a/test/FixIt/fixit-cxx0x.cpp b/test/FixIt/fixit-cxx0x.cpp
index c3c1dcf20f..2addad4696 100644
--- a/test/FixIt/fixit-cxx0x.cpp
+++ b/test/FixIt/fixit-cxx0x.cpp
@@ -1,6 +1,6 @@
// RUN: %clang_cc1 -verify -std=c++0x %s
// RUN: cp %s %t
-// RUN: not %clang_cc1 -x c++ -std=c++0x -fixit %t
+// RUN: not %clang_cc1 -x c++ -std=c++0x -Werror -fixit %t
// RUN: %clang_cc1 -Wall -pedantic -x c++ -std=c++0x %t
/* This is a test of the various code modification hints that only
@@ -17,3 +17,45 @@ void x() {
using ::T = void; // expected-error {{name defined in alias declaration must be an identifier}}
using typename U = void; // expected-error {{name defined in alias declaration must be an identifier}}
using typename ::V = void; // expected-error {{name defined in alias declaration must be an identifier}}
+
+namespace Constexpr {
+ extern constexpr int a; // expected-error {{must be a definition}}
+ // -> extern const int a;
+
+ extern constexpr int *b; // expected-error {{must be a definition}}
+ // -> extern int *const b;
+
+ extern constexpr int &c; // expected-error {{must be a definition}}
+ // -> extern int &b;
+
+ extern constexpr const int d; // expected-error {{must be a definition}}
+ // -> extern const int d;
+
+ int z;
+ constexpr int a = 0;
+ constexpr int *b = &z;
+ constexpr int &c = z;
+ constexpr int d = a;
+
+ // FIXME: Provide FixIts for static data members too.
+#if 0
+ struct S {
+ static constexpr int a = 0;
+
+ static constexpr int b; // xpected-error {{requires an initializer}}
+ // -> const int b;
+ };
+
+ constexpr int S::a; // xpected-error {{requires an initializer}}
+ // -> const int S::a;
+
+ constexpr int S::b = 0;
+#endif
+
+ struct S {
+ static const double d = 0.0; // expected-warning {{accepted as an extension}}
+ // -> constexpr static const double d = 0.0;
+ static char *const p = 0; // expected-warning {{accepted as an extension}}
+ // -> constexpr static char *const p = 0;
+ };
+}