[clang] 1a0a030 - Add documentation for -Wwrite-strings

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 20 13:14:12 PDT 2023


Author: Aaron Ballman
Date: 2023-04-20T16:14:03-04:00
New Revision: 1a0a0305c03dc6cf42d042f39199ca37c16f6dda

URL: https://github.com/llvm/llvm-project/commit/1a0a0305c03dc6cf42d042f39199ca37c16f6dda
DIFF: https://github.com/llvm/llvm-project/commit/1a0a0305c03dc6cf42d042f39199ca37c16f6dda.diff

LOG: Add documentation for -Wwrite-strings

This is the first instance where we've really needed to add
documentation for a diagnostic group, but -Wwrite-strings really
deserves it.

This warning option changes the semantic behavior of code, so enabling
it can cause code to break (and disabling it can too). That's worth
calling out loudly in our documentation.

Added: 
    

Modified: 
    clang/include/clang/Basic/Diagnostic.td
    clang/include/clang/Basic/DiagnosticDocs.td
    clang/include/clang/Basic/DiagnosticGroups.td

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/Diagnostic.td b/clang/include/clang/Basic/Diagnostic.td
index 21de05b707a58..503b833e63bbf 100644
--- a/clang/include/clang/Basic/Diagnostic.td
+++ b/clang/include/clang/Basic/Diagnostic.td
@@ -55,11 +55,11 @@ class DiagCategory<string Name> {
 }
 
 // Diagnostic Groups.
-class DiagGroup<string Name, list<DiagGroup> subgroups = []> {
+class DiagGroup<string Name, list<DiagGroup> subgroups = [], code docs = [{}]> {
   string GroupName = Name;
   list<DiagGroup> SubGroups = subgroups;
   string CategoryName = "";
-  code Documentation = [{}];
+  code Documentation = docs;
 }
 class InGroup<DiagGroup G> { DiagGroup Group = G; }
 //class IsGroup<string Name> { DiagGroup Group = DiagGroup<Name>; }

diff  --git a/clang/include/clang/Basic/DiagnosticDocs.td b/clang/include/clang/Basic/DiagnosticDocs.td
index bf88d5d04567e..e9862422b4997 100644
--- a/clang/include/clang/Basic/DiagnosticDocs.td
+++ b/clang/include/clang/Basic/DiagnosticDocs.td
@@ -81,3 +81,9 @@ Diagnostic flags
 }];
 }
 
+defvar GCCWriteStringsDocs = [{
+**Note:** enabling this warning in C will change the semantic behavior of the
+program by treating all string literals as having type ``const char *``
+instead of ``char *``. This can cause unexpected behaviors with type-sensitive
+constructs like ``_Generic``.
+}];

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td
index 31f64f4eceb7c..0ee43fb8837a1 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -847,7 +847,8 @@ def WritableStrings : DiagGroup<"writable-strings", [DeprecatedWritableStr]>;
 //
 // FIXME: Should this affect C++11 (where this is an error,
 //        not just deprecated) or not?
-def GCCWriteStrings : DiagGroup<"write-strings" , [WritableStrings]>;
+def GCCWriteStrings : DiagGroup<"write-strings" , [WritableStrings],
+                                GCCWriteStringsDocs>;
 
 def CharSubscript : DiagGroup<"char-subscripts">;
 def LargeByValueCopy : DiagGroup<"large-by-value-copy">;


        


More information about the cfe-commits mailing list