]> granicus.if.org Git - clang/commitdiff
Sema: Diagnose global replacement functions declared as inline
authorDavid Majnemer <david.majnemer@gmail.com>
Sun, 20 Oct 2013 05:40:29 +0000 (05:40 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Sun, 20 Oct 2013 05:40:29 +0000 (05:40 +0000)
This fixes PR17591.

N.B. This actually goes beyond what the standard mandates by requiring
the restriction to hold for declarations instead of definitions.  This
is believed to be a defect in the standard and an LWG issue has been
submitted.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193044 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDecl.cpp
test/SemaCXX/new-delete.cpp

index d8fef68d48c401878535c6e76ed62fe0e1324627..55c4e9d57b5b29c196fa757295a934ed4b76eff8 100644 (file)
@@ -5900,6 +5900,8 @@ def err_operator_new_delete_declared_in_namespace : Error<
   "%0 cannot be declared inside a namespace">;
 def err_operator_new_delete_declared_static : Error<
   "%0 cannot be declared static in global scope">;
+def err_operator_new_delete_declared_inline : Error<
+  "%0 cannot be declared 'inline'">;
 def err_operator_new_delete_invalid_result_type : Error<
   "%0 must return type %1">;
 def err_operator_new_delete_dependent_result_type : Error<
index d7c4f7834f9cb3b60ad9945d03d0fa8a74f74766..176fe8a1cf2c62ff13c6068ad2709f93be2730d2 100644 (file)
@@ -6804,6 +6804,13 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
       NewFD->setType(Context.getFunctionType(FPT->getResultType(),
                                              FPT->getArgTypes(), EPI));
     }
+
+    // C++11 [replacement.functions]p3:
+    //  The program's definitions shall not be specified as inline.
+    if (isInline && NewFD->isReplaceableGlobalAllocationFunction())
+      Diag(D.getDeclSpec().getInlineSpecLoc(),
+           diag::err_operator_new_delete_declared_inline)
+        << NewFD->getDeclName();
   }
 
   // Filter out previous declarations that don't match the scope.
index 898c6e0879a1f476a78f4294a97eaf789986f79d..de26cad62e15a978da423383ae2ae4dd0109515b 100644 (file)
@@ -24,6 +24,8 @@ 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-error {{'operator delete' cannot be declared 'inline'}}
+
 struct foo { };
 
 void good_news()