aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Redl <sebastian.redl@getdesigned.at>2010-06-09 21:19:43 +0000
committerSebastian Redl <sebastian.redl@getdesigned.at>2010-06-09 21:19:43 +0000
commit737801257f795632175517ffce4a80c62fc7bff7 (patch)
treeaa4afbafa99ad23dc6f2e88e6a1618e50d10c913
parent515ddd8f7a36fc2684492c13665642153fc690c0 (diff)
Commit my WIP on constexpr support. This commit: an XFAILed test and treating constexpr as a top-level const.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@105752 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaType.cpp7
-rw-r--r--test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p1.cpp78
2 files changed, 84 insertions, 1 deletions
diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp
index 8327fd2686..bec929dabf 100644
--- a/lib/Sema/SemaType.cpp
+++ b/lib/Sema/SemaType.cpp
@@ -860,7 +860,7 @@ QualType Sema::BuildMemberPointerType(QualType T, QualType Class,
T = Context.getCanonicalType(T);
}
- // C++ 8.3.3p3: A pointer to member shall not pointer to ... a member
+ // C++ 8.3.3p3: A pointer to member shall not point to ... a member
// with reference type, or "cv void."
if (T->isReferenceType()) {
Diag(Loc, diag::err_illegal_decl_mempointer_to_reference)
@@ -1335,6 +1335,11 @@ TypeSourceInfo *Sema::GetTypeForDeclarator(Declarator &D, Scope *S,
}
}
+ // If there's a constexpr specifier, treat it as a top-level const.
+ if (D.getDeclSpec().isConstexprSpecified()) {
+ T.addConst();
+ }
+
// Process any function attributes we might have delayed from the
// declaration-specifiers.
ProcessDelayedFnAttrs(*this, T, FnAttrsFromDeclSpec);
diff --git a/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p1.cpp b/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p1.cpp
new file mode 100644
index 0000000000..cd71d55fc5
--- /dev/null
+++ b/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p1.cpp
@@ -0,0 +1,78 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// XFAIL: *
+
+struct notlit {
+ notlit() {}
+};
+struct notlit2 {
+ notlit2() {}
+};
+
+// valid declarations
+constexpr int i1 = 0;
+constexpr int f1() { return 0; }
+struct s1 {
+ constexpr static int mi = 0;
+};
+
+// invalid declarations
+// not a definition of an object
+constexpr extern int i2; // x
+// not a literal type
+constexpr notlit nl1; // x
+// function parameters
+void f2(constexpr int i) {} // x
+// non-static member
+struct s2 {
+ constexpr int mi; // x
+};
+// redeclaration mismatch
+constexpr int f3(); // n
+int f3(); // x
+int f4(); // n
+constexpr int f4(); // x
+
+// template stuff
+template <typename T>
+constexpr T ft(T t) { return t; }
+
+// specialization can differ in constepxr
+template <>
+notlit ft(notlit nl) { return nl; }
+
+constexpr int i3 = ft(1);
+
+void test() {
+ // ignore constexpr when instantiating with non-literal
+ notlit2 nl2;
+ (void)ft(nl2);
+}
+
+// Examples from the standard:
+constexpr int square(int x);
+constexpr int bufsz = 1024;
+
+constexpr struct pixel { // x
+ int x;
+ int y;
+ constexpr pixel(int);
+};
+
+constexpr pixel::pixel(int a)
+ : x(square(a)), y(square(a))
+ { }
+
+constexpr pixel small(2); // x (no definition of square(int) yet, so can't
+ // constexpr-eval pixel(int))
+
+constexpr int square(int x) {
+ return x * x;
+}
+
+constexpr pixel large(4); // now valid
+
+int next(constexpr int x) { // x
+ return x + 1;
+}
+
+extern constexpr int memsz; // x