r194916 - If a replaceable global operator new/delete is marked inline, don't warn if

Richard Smith richard-llvm at metafoo.co.uk
Fri Nov 15 17:57:09 PST 2013


Author: rsmith
Date: Fri Nov 15 19:57:09 2013
New Revision: 194916

URL: http://llvm.org/viewvc/llvm-project?rev=194916&view=rev
Log:
If a replaceable global operator new/delete is marked inline, don't warn if
it's also __attribute__((used)), since that undoes the problematic part of
'inline'.

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/SemaCXX/new-delete.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=194916&r1=194915&r2=194916&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Nov 15 19:57:09 2013
@@ -6872,15 +6872,6 @@ Sema::ActOnFunctionDeclarator(Scope *S,
       NewFD->setType(Context.getFunctionType(FPT->getResultType(),
                                              FPT->getArgTypes(), EPI));
     }
-
-    // C++11 [replacement.functions]p3:
-    //  The program's definitions shall not be specified as inline.
-    //
-    // N.B. We diagnose declarations instead of definitions per LWG issue 2340.
-    if (isInline && NewFD->isReplaceableGlobalAllocationFunction())
-      Diag(D.getDeclSpec().getInlineSpecLoc(),
-           diag::ext_operator_new_delete_declared_inline)
-        << NewFD->getDeclName();
   }
 
   // Filter out previous declarations that don't match the scope.
@@ -7015,6 +7006,20 @@ Sema::ActOnFunctionDeclarator(Scope *S,
             Previous.getResultKind() != LookupResult::FoundOverloaded) &&
            "previous declaration set still overloaded");
   } else {
+    // C++11 [replacement.functions]p3:
+    //  The program's definitions shall not be specified as inline.
+    //
+    // N.B. We diagnose declarations instead of definitions per LWG issue 2340.
+    //
+    // Suppress the diagnostic if the function is __attribute__((used)), since
+    // that forces an external definition to be emitted.
+    if (D.getDeclSpec().isInlineSpecified() &&
+        NewFD->isReplaceableGlobalAllocationFunction() &&
+        !NewFD->hasAttr<UsedAttr>())
+      Diag(D.getDeclSpec().getInlineSpecLoc(),
+           diag::ext_operator_new_delete_declared_inline)
+        << NewFD->getDeclName();
+
     // If the declarator is a template-id, translate the parser's template 
     // argument list into our AST format.
     if (D.getName().getKind() == UnqualifiedId::IK_TemplateId) {

Modified: cfe/trunk/test/SemaCXX/new-delete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/new-delete.cpp?rev=194916&r1=194915&r2=194916&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/new-delete.cpp (original)
+++ cfe/trunk/test/SemaCXX/new-delete.cpp Fri Nov 15 19:57:09 2013
@@ -18,14 +18,19 @@ struct V : U
 {
 };
 
+inline void operator delete(void *); // expected-warning {{replacement function 'operator delete' cannot be declared 'inline'}}
+
+__attribute__((used))
+inline void *operator new(size_t) { // no warning, due to __attribute__((used))
+  return 0;
+}
+
 // PR5823
 void* operator new(const size_t); // expected-note 2 {{candidate}}
 void* operator new(size_t, int*); // expected-note 3 {{candidate}}
 void* operator new(size_t, float*); // expected-note 3 {{candidate}}
 void* operator new(size_t, S); // expected-note 2 {{candidate}}
 
-inline void operator delete(void *); // expected-warning {{replacement function 'operator delete' cannot be declared 'inline'}}
-
 struct foo { };
 
 void good_news()





More information about the cfe-commits mailing list