r222569 - Sema: Don't permit variably modified types in typeid
David Majnemer
david.majnemer at gmail.com
Fri Nov 21 13:09:12 PST 2014
Author: majnemer
Date: Fri Nov 21 15:09:12 2014
New Revision: 222569
URL: http://llvm.org/viewvc/llvm-project?rev=222569&view=rev
Log:
Sema: Don't permit variably modified types in typeid
GCC and ICC both reject this and the 'Runtime-sized arrays with
automatic storage duration' (N3639) paper forbade this as well.
Previously, we would crash on our way to mangling.
This fixes PR21632.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/test/SemaCXX/typeid.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=222569&r1=222568&r2=222569&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Nov 21 15:09:12 2014
@@ -5303,6 +5303,7 @@ def err_uuidof_without_guid : Error<
def err_uuidof_with_multiple_guids : Error<
"cannot call operator __uuidof on a type with multiple GUIDs">;
def err_incomplete_typeid : Error<"'typeid' of incomplete type %0">;
+def err_variably_modified_typeid : Error<"'typeid' of variably modified type %0">;
def err_static_illegal_in_new : Error<
"the 'static' modifier for the array size is not legal in new expressions">;
def err_array_new_needs_size : Error<
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=222569&r1=222568&r2=222569&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Fri Nov 21 15:09:12 2014
@@ -384,6 +384,9 @@ ExprResult Sema::BuildCXXTypeId(QualType
RequireCompleteType(TypeidLoc, T, diag::err_incomplete_typeid))
return ExprError();
+ if (T->isVariablyModifiedType())
+ return ExprError(Diag(TypeidLoc, diag::err_variably_modified_typeid) << T);
+
return new (Context) CXXTypeidExpr(TypeInfoType.withConst(), Operand,
SourceRange(TypeidLoc, RParenLoc));
}
@@ -438,6 +441,10 @@ ExprResult Sema::BuildCXXTypeId(QualType
}
}
+ if (E->getType()->isVariablyModifiedType())
+ return ExprError(Diag(TypeidLoc, diag::err_variably_modified_typeid)
+ << E->getType());
+
return new (Context) CXXTypeidExpr(TypeInfoType.withConst(), E,
SourceRange(TypeidLoc, RParenLoc));
}
Modified: cfe/trunk/test/SemaCXX/typeid.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/typeid.cpp?rev=222569&r1=222568&r2=222569&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/typeid.cpp (original)
+++ cfe/trunk/test/SemaCXX/typeid.cpp Fri Nov 21 15:09:12 2014
@@ -21,3 +21,9 @@ void g1(X &x) {
(void)typeid(X&); // expected-error{{'typeid' of incomplete type 'X'}}
(void)typeid(x); // expected-error{{'typeid' of incomplete type 'X'}}
}
+
+void h(int i) {
+ char V[i];
+ typeid(V); // expected-error{{'typeid' of variably modified type 'char [i]'}}
+ typeid(char [i]); // expected-error{{'typeid' of variably modified type 'char [i]'}}
+}
More information about the cfe-commits
mailing list