Skip to content

Commit

Permalink
Add documentation for -Wwrite-strings
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AaronBallman committed Apr 20, 2023
1 parent e73fa20 commit 1a0a030
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions clang/include/clang/Basic/Diagnostic.td
Original file line number Diff line number Diff line change
Expand Up @@ -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>; }
Expand Down
6 changes: 6 additions & 0 deletions clang/include/clang/Basic/DiagnosticDocs.td
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
}];
3 changes: 2 additions & 1 deletion clang/include/clang/Basic/DiagnosticGroups.td
Original file line number Diff line number Diff line change
Expand Up @@ -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">;
Expand Down

0 comments on commit 1a0a030

Please sign in to comment.