From f411196d15a92f415d6a042b787f8fccc1ffec42 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 20 Oct 2011 18:35:58 +0000 Subject: [PATCH] 'extern template' is a C++11 feature. Add an Extension for C++98 (this matches gcc's behaviour), and a -Wc++98-compat-pedantic warning for C++11. llvm-svn: 142597 --- clang/include/clang/Basic/DiagnosticParseKinds.td | 5 +++++ clang/lib/Parse/Parser.cpp | 3 +++ clang/test/CXX/temp/temp.spec/temp.explicit/p4.cpp | 2 +- clang/test/SemaCXX/cxx98-compat-pedantic.cpp | 3 +++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td index 62470582870c..32e9a0837014 100644 --- a/clang/include/clang/Basic/DiagnosticParseKinds.td +++ b/clang/include/clang/Basic/DiagnosticParseKinds.td @@ -469,6 +469,11 @@ def err_missing_dependent_template_keyword : Error< def warn_missing_dependent_template_keyword : ExtWarn< "use 'template' keyword to treat '%0' as a dependent template name">; +def ext_extern_template : Extension< + "extern templates are a C++11 extension">, InGroup; +def warn_cxx98_compat_extern_template : Warning< + "extern templates are incompatible with C++98">, + InGroup, DefaultIgnore; def warn_static_inline_explicit_inst_ignored : Warning< "ignoring '%select{static|inline}0' keyword on explicit template " "instantiation">; diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index 2a1e2a2de899..2e0c46dbdbfe 100644 --- a/clang/lib/Parse/Parser.cpp +++ b/clang/lib/Parse/Parser.cpp @@ -642,6 +642,9 @@ Parser::ParseExternalDeclaration(ParsedAttributesWithRange &attrs, // Extern templates SourceLocation ExternLoc = ConsumeToken(); SourceLocation TemplateLoc = ConsumeToken(); + Diag(ExternLoc, getLang().CPlusPlus0x ? + diag::warn_cxx98_compat_extern_template : + diag::ext_extern_template) << SourceRange(ExternLoc, TemplateLoc); SourceLocation DeclEnd; return Actions.ConvertDeclToDeclGroup( ParseExplicitInstantiation(ExternLoc, TemplateLoc, DeclEnd)); diff --git a/clang/test/CXX/temp/temp.spec/temp.explicit/p4.cpp b/clang/test/CXX/temp/temp.spec/temp.explicit/p4.cpp index d30437411513..09c428e01df3 100644 --- a/clang/test/CXX/temp/temp.spec/temp.explicit/p4.cpp +++ b/clang/test/CXX/temp/temp.spec/temp.explicit/p4.cpp @@ -43,6 +43,6 @@ namespace test0 { // inappropriately instantiating this template. void *ptr = x; } - extern template class foo; + extern template class foo; // expected-warning {{extern templates are a C++11 extension}} template class foo; } diff --git a/clang/test/SemaCXX/cxx98-compat-pedantic.cpp b/clang/test/SemaCXX/cxx98-compat-pedantic.cpp index 28fc23a0a763..00532d5ac073 100644 --- a/clang/test/SemaCXX/cxx98-compat-pedantic.cpp +++ b/clang/test/SemaCXX/cxx98-compat-pedantic.cpp @@ -29,3 +29,6 @@ struct ConvertToInt { operator int(); }; int *ArraySizeConversion = new int[ConvertToInt()]; // expected-warning {{implicit conversion from array size expression of type 'ConvertToInt' to integral type 'int' is incompatible with C++98}} + +template class ExternTemplate {}; +extern template class ExternTemplate; // expected-warning {{extern templates are incompatible with C++98}} -- GitLab