From: Eli Friedman Date: Thu, 20 Jun 2013 22:55:04 +0000 (+0000) Subject: Don't allow __attribute__((common)) in C++. PR16330. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3e1aca289f56310f20f3d97e154337275adf17a4;p=clang Don't allow __attribute__((common)) in C++. PR16330. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184493 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index cf1e6dc3ac..49e37faae7 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -1826,6 +1826,8 @@ def err_format_attribute_result_not : Error<"function does not return %0">; def err_format_attribute_implicit_this_format_string : Error< "format attribute cannot specify the implicit this argument as the format " "string">; +def err_common_not_supported_cplusplus : Error< + "common attribute is not supported in C++">; def warn_unknown_method_family : Warning<"unrecognized method family">; def err_init_method_bad_return_type : Error< "init methods must return an object pointer type, not %0">; diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 9a68ca5a75..a254caeff7 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -1746,6 +1746,12 @@ static void handleNoCommonAttr(Sema &S, Decl *D, const AttributeList &Attr) { static void handleCommonAttr(Sema &S, Decl *D, const AttributeList &Attr) { assert(!Attr.isInvalid()); + + if (S.LangOpts.CPlusPlus) { + S.Diag(Attr.getLoc(), diag::err_common_not_supported_cplusplus); + return; + } + if (isa(D)) D->addAttr(::new (S.Context) CommonAttr(Attr.getRange(), S.Context, diff --git a/test/SemaCXX/attr-common.cpp b/test/SemaCXX/attr-common.cpp new file mode 100644 index 0000000000..58b30133f5 --- /dev/null +++ b/test/SemaCXX/attr-common.cpp @@ -0,0 +1,3 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +__attribute__((common)) int x; // expected-error {{common attribute is not supported in C++}}