[cfe-commits] r89656 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaStmt.cpp test/SemaCXX/switch.cpp
Douglas Gregor
dgregor at apple.com
Mon Nov 23 05:53:21 PST 2009
Author: dgregor
Date: Mon Nov 23 07:53:21 2009
New Revision: 89656
URL: http://llvm.org/viewvc/llvm-project?rev=89656&view=rev
Log:
Require a class type to be complete before probing its conversion
functions for a switch condition's conversion to integral or
enumeration type.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaStmt.cpp
cfe/trunk/test/SemaCXX/switch.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=89656&r1=89655&r2=89656&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Nov 23 07:53:21 2009
@@ -2299,6 +2299,8 @@
"conversion to %select{integral|enumeration}0 type %1">;
def err_switch_explicit_conversion : Error<
"switch condition type %0 requires explicit conversion to %1">;
+def err_switch_incomplete_class_type : Error<
+ "switch condition has incomplete class type %0">;
def warn_empty_if_body : Warning<
"if statement has empty body">, InGroup<EmptyBody>;
def err_va_start_used_in_non_variadic_function : Error<
Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=89656&r1=89655&r2=89656&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Mon Nov 23 07:53:21 2009
@@ -391,6 +391,13 @@
// conversion is used in place of the original condition for the remainder
// of this section. Integral promotions are performed.
if (!CondExpr->isTypeDependent()) {
+ // Make sure that the condition expression has a complete type,
+ // otherwise we'll never find any conversions.
+ if (RequireCompleteType(SwitchLoc, CondType,
+ PDiag(diag::err_switch_incomplete_class_type)
+ << CondExpr->getSourceRange()))
+ return StmtError();
+
llvm::SmallVector<CXXConversionDecl *, 4> ViableConversions;
llvm::SmallVector<CXXConversionDecl *, 4> ExplicitConversions;
if (const RecordType *RecordTy = CondType->getAs<RecordType>()) {
Modified: cfe/trunk/test/SemaCXX/switch.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/switch.cpp?rev=89656&r1=89655&r2=89656&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/switch.cpp (original)
+++ cfe/trunk/test/SemaCXX/switch.cpp Mon Nov 23 07:53:21 2009
@@ -33,3 +33,10 @@
switch (B()) { // expected-error{{multiple conversions}}
}
}
+
+struct C; // expected-note{{forward declaration}}
+
+void x3(C &c) {
+ switch (c) { // expected-error{{incomplete class type}}
+ }
+}
More information about the cfe-commits
mailing list