[PATCH] D44948: Add diagnostic -Waggregate-ctors, "aggregate type has user-declared constructors"

Arthur O'Dwyer via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 27 12:40:04 PDT 2018


Quuxplusone created this revision.
Herald added a subscriber: cfe-commits.

This new warning diagnoses any aggregate class/struct/union type which has user-declared constructors, in order to test the hypothesis that real code does not (intentionally) contain such animals.

      

If no real code triggers this diagnostic, then it would be plausible to change the definition of "aggregate type" in C++2a so that types triggering this diagnostic would no longer be considered aggregate types at all.


Repository:
  rC Clang

https://reviews.llvm.org/D44948

Files:
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaDeclCXX.cpp


Index: lib/Sema/SemaDeclCXX.cpp
===================================================================
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -5907,6 +5907,10 @@
            diag::warn_non_virtual_dtor) << Context.getRecordType(Record);
   }
 
+  if (Record->isAggregate() && Record->hasUserDeclaredConstructor()) {
+    Diag(Record->getLocation(), diag::warn_aggregate_with_user_declared_constructor);
+  }
+
   if (Record->isAbstract()) {
     if (FinalAttr *FA = Record->getAttr<FinalAttr>()) {
       Diag(Record->getLocation(), diag::warn_abstract_final_class)
Index: include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -6466,6 +6466,9 @@
 def warn_jump_out_of_seh_finally : Warning<
   "jump out of __finally block has undefined behavior">,
   InGroup<DiagGroup<"jump-seh-finally">>;
+def warn_aggregate_with_user_declared_constructor : Warning<
+  "aggregate type has user-declared constructors">,
+  InGroup<AggregateCtors>;
 def warn_non_virtual_dtor : Warning<
   "%0 has virtual functions but non-virtual destructor">,
   InGroup<NonVirtualDtor>, DefaultIgnore;
Index: include/clang/Basic/DiagnosticGroups.td
===================================================================
--- include/clang/Basic/DiagnosticGroups.td
+++ include/clang/Basic/DiagnosticGroups.td
@@ -99,6 +99,7 @@
 def DeleteIncomplete : DiagGroup<"delete-incomplete">;
 def DeleteNonVirtualDtor : DiagGroup<"delete-non-virtual-dtor">;
 def AbstractFinalClass : DiagGroup<"abstract-final-class">;
+def AggregateCtors : DiagGroup<"aggregate-ctors">;
 
 def CXX11CompatDeprecatedWritableStr :
   DiagGroup<"c++11-compat-deprecated-writable-strings">;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44948.139983.patch
Type: text/x-patch
Size: 1814 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180327/259ac158/attachment.bin>


More information about the cfe-commits mailing list