[cfe-commits] r132980 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp test/SemaCXX/i-c-e-cxx.cpp
Chris Lattner
sabre at nondot.org
Mon Jun 13 22:46:29 PDT 2011
Author: lattner
Date: Tue Jun 14 00:46:29 2011
New Revision: 132980
URL: http://llvm.org/viewvc/llvm-project?rev=132980&view=rev
Log:
fix rdar://9204520 - Accept int(0.85 * 10) as an initializer in a class member
as an extension.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaCXX/i-c-e-cxx.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=132980&r1=132979&r2=132980&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Jun 14 00:46:29 2011
@@ -3542,6 +3542,9 @@
def err_in_class_initializer_non_constant : Error<
"in-class initializer is not a constant expression">;
+def ext_in_class_initializer_non_constant : Extension<
+ "in-class initializer is not a constant expression, accepted as an extension">;
+
// C++ anonymous unions and GNU anonymous structs/unions
def ext_anonymous_union : Extension<
"anonymous unions are a GNU extension in C">, InGroup<GNU>;
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=132980&r1=132979&r2=132980&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Jun 14 00:46:29 2011
@@ -5369,15 +5369,23 @@
// We allow integer constant expressions in all cases.
} else if (T->isIntegralOrEnumerationType()) {
- if (!Init->isValueDependent()) {
- // Check whether the expression is a constant expression.
- llvm::APSInt Value;
- SourceLocation Loc;
- if (!Init->isIntegerConstantExpr(Value, Context, &Loc)) {
- Diag(Loc, diag::err_in_class_initializer_non_constant)
- << Init->getSourceRange();
- VDecl->setInvalidDecl();
- }
+ // Check whether the expression is a constant expression.
+ SourceLocation Loc;
+ if (Init->isValueDependent())
+ ; // Nothing to check.
+ else if (Init->isIntegerConstantExpr(Context, &Loc))
+ ; // Ok, it's an ICE!
+ else if (Init->isEvaluatable(Context)) {
+ // If we can constant fold the initializer through heroics, accept it,
+ // but report this as a use of an extension for -pedantic.
+ Diag(Loc, diag::ext_in_class_initializer_non_constant)
+ << Init->getSourceRange();
+ } else {
+ // Otherwise, this is some crazy unknown case. Report the issue at the
+ // location provided by the isIntegerConstantExpr failed check.
+ Diag(Loc, diag::err_in_class_initializer_non_constant)
+ << Init->getSourceRange();
+ VDecl->setInvalidDecl();
}
// We allow floating-point constants as an extension in C++03, and
Modified: cfe/trunk/test/SemaCXX/i-c-e-cxx.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/i-c-e-cxx.cpp?rev=132980&r1=132979&r2=132980&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/i-c-e-cxx.cpp (original)
+++ cfe/trunk/test/SemaCXX/i-c-e-cxx.cpp Tue Jun 14 00:46:29 2011
@@ -42,3 +42,16 @@
void pr6373(const unsigned x = 0) {
unsigned max = 80 / x;
}
+
+
+// rdar://9204520
+namespace rdar9204520 {
+
+struct A {
+ static const int B = int(0.75 * 1000 * 1000);
+};
+
+int foo() { return A::B; }
+}
+
+
More information about the cfe-commits
mailing list