[cfe-commits] r151947 - in /cfe/trunk: include/clang/Basic/DiagnosticParseKinds.td lib/Parse/ParseDecl.cpp test/SemaCXX/warn-thread-safety-analysis.cpp
DeLesley Hutchins
delesley at google.com
Fri Mar 2 14:29:51 PST 2012
Author: delesley
Date: Fri Mar 2 16:29:50 2012
New Revision: 151947
URL: http://llvm.org/viewvc/llvm-project?rev=151947&view=rev
Log:
Issue warning when late-parsed attributes have no declaration.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=151947&r1=151946&r2=151947&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Fri Mar 2 16:29:50 2012
@@ -154,6 +154,9 @@
def warn_attribute_on_function_definition : Warning<
"GCC does not allow %0 attribute in this position on a function definition">,
InGroup<GccCompat>;
+def warn_attribute_no_decl : Warning<
+ "attribute %0 ignored, because it is not attached to a declaration">,
+ InGroup<IgnoredAttributes>;
def err_expected_method_body : Error<"expected method body">;
def err_invalid_token_after_toplevel_declarator : Error<
"expected ';' after top level declarator">;
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=151947&r1=151946&r2=151947&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Fri Mar 2 16:29:50 2012
@@ -774,10 +774,6 @@
ParsedAttributes Attrs(AttrFactory);
SourceLocation endLoc;
- // Late parsed attributes must be attached to Decls by hand. If there
- // are no Decls, then this was not done properly.
- assert(LA.Decls.size() > 0 && "No decls attached to late parsed attribute");
-
if (LA.Decls.size() == 1) {
Decl *D = LA.Decls[0];
@@ -802,10 +798,12 @@
if (HasTemplateScope) {
TempScope.Exit();
}
- } else {
+ } else if (LA.Decls.size() > 0) {
// If there are multiple decls, then the decl cannot be within the
// function scope.
ParseGNUAttributeArgs(&LA.AttrName, LA.AttrNameLoc, Attrs, &endLoc);
+ } else {
+ Diag(Tok, diag::warn_attribute_no_decl) << LA.AttrName.getName();
}
for (unsigned i = 0, ni = LA.Decls.size(); i < ni; ++i) {
Modified: cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp?rev=151947&r1=151946&r2=151947&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp Fri Mar 2 16:29:50 2012
@@ -2155,3 +2155,16 @@
} // end namespace TestMultiDecl
+
+namespace WarnNoDecl {
+
+class Foo {
+ void foo(int a); __attribute__(( // \
+ // expected-warning {{declaration does not declare anything}}
+ exclusive_locks_required(a))); // \
+ // expected-warning {{attribute exclusive_locks_required ignored}}
+};
+
+} // end namespace WarnNoDecl
+
+
More information about the cfe-commits
mailing list