[cfe-commits] r127967 - in /cfe/trunk: lib/Sema/SemaType.cpp test/SemaCXX/cxx0x-constexpr-const.cpp
Peter Collingbourne
peter at pcc.me.uk
Sun Mar 20 01:06:46 PDT 2011
Author: pcc
Date: Sun Mar 20 03:06:45 2011
New Revision: 127967
URL: http://llvm.org/viewvc/llvm-project?rev=127967&view=rev
Log:
Only objects are declared const by a constexpr specifier, per C++0x [dcl.constexpr]p9
Added:
cfe/trunk/test/SemaCXX/cxx0x-constexpr-const.cpp
Modified:
cfe/trunk/lib/Sema/SemaType.cpp
Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=127967&r1=127966&r2=127967&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Sun Mar 20 03:06:45 2011
@@ -2116,8 +2116,10 @@
// Diagnose any ignored type attributes.
if (!T.isNull()) state.diagnoseIgnoredTypeAttrs(T);
- // If there's a constexpr specifier, treat it as a top-level const.
- if (D.getDeclSpec().isConstexprSpecified()) {
+ // C++0x [dcl.constexpr]p9:
+ // A constexpr specifier used in an object declaration declares the object
+ // as const.
+ if (D.getDeclSpec().isConstexprSpecified() && T->isObjectType()) {
T.addConst();
}
Added: cfe/trunk/test/SemaCXX/cxx0x-constexpr-const.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx0x-constexpr-const.cpp?rev=127967&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx0x-constexpr-const.cpp (added)
+++ cfe/trunk/test/SemaCXX/cxx0x-constexpr-const.cpp Sun Mar 20 03:06:45 2011
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s
+
+constexpr int x = 1;
+constexpr int id(int x) { return x; }
+
+void foo(void) {
+ x = 2; // expected-error {{read-only variable is not assignable}}
+ int (*idp)(int) = id;
+}
+
More information about the cfe-commits
mailing list