Skip to content

Commit

Permalink
Error when using typeid() with -fno-rtti. PR 12888.
Browse files Browse the repository at this point in the history
llvm-svn: 157139
  • Loading branch information
nico committed May 20, 2012
1 parent 0229000 commit 1b7f39d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -4392,6 +4392,9 @@ def err_invalid_declarator_in_function : Error<
def err_not_tag_in_scope : Error<
"no %select{struct|union|class|enum}0 named %1 in %2">;

def err_no_typeid_with_fno_rtti : Error<
"cannot use typeid with -fno-rtti">;

def err_cannot_form_pointer_to_member_of_reference_type : Error<
"cannot form a pointer-to-member to member %0 of reference type %1">;
def err_incomplete_object_call : Error<
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Sema/SemaExprCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,10 @@ Sema::ActOnCXXTypeid(SourceLocation OpLoc, SourceLocation LParenLoc,
return ExprError(Diag(OpLoc, diag::err_need_header_before_typeid));
}

if (!getLangOpts().RTTI) {
return ExprError(Diag(OpLoc, diag::err_no_typeid_with_fno_rtti));
}

QualType TypeInfoType = Context.getTypeDeclType(CXXTypeInfoDecl);

if (isType) {
Expand Down
10 changes: 10 additions & 0 deletions clang/test/SemaCXX/no-rtti.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: %clang_cc1 -fsyntax-only -verify -fno-rtti %s

namespace std {
class type_info;
}

void f()
{
(void)typeid(int); // expected-error {{cannot use typeid with -fno-rtti}}
}

0 comments on commit 1b7f39d

Please sign in to comment.