diff options
| author | David Majnemer <david.majnemer@gmail.com> | 2014-11-21 21:09:12 +0000 |
|---|---|---|
| committer | David Majnemer <david.majnemer@gmail.com> | 2014-11-21 21:09:12 +0000 |
| commit | 6f3150a7d2626ebfcffdef01d91f86daaffc662b (patch) | |
| tree | 8a2bc343c291a8833ff8ee1a6c19b873c8b9b769 | |
| parent | d5178014938df1cd5117230950bfd935d14f2f9c (diff) | |
| download | bcm5719-llvm-6f3150a7d2626ebfcffdef01d91f86daaffc662b.tar.gz bcm5719-llvm-6f3150a7d2626ebfcffdef01d91f86daaffc662b.zip | |
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.
llvm-svn: 222569
| -rw-r--r-- | clang/include/clang/Basic/DiagnosticSemaKinds.td | 1 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaExprCXX.cpp | 7 | ||||
| -rw-r--r-- | clang/test/SemaCXX/typeid.cpp | 6 |
3 files changed, 14 insertions, 0 deletions
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 310a9b2a2ff..9639b3ce42c 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -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< diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index 93996685105..c71a4e93bbd 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -384,6 +384,9 @@ ExprResult Sema::BuildCXXTypeId(QualType TypeInfoType, 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 TypeInfoType, } } + 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)); } diff --git a/clang/test/SemaCXX/typeid.cpp b/clang/test/SemaCXX/typeid.cpp index d3a2a28deb8..48fcce0b492 100644 --- a/clang/test/SemaCXX/typeid.cpp +++ b/clang/test/SemaCXX/typeid.cpp @@ -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]'}} +} |

