Skip to content

Commit 3971cf1

Browse files
authored
Merge pull request #8639 from apple/kphillips/wformat-carve-out
[🍒 stable/20240408] Carving out -Wformat warning about scoped enums into a subwarning
2 parents 0c503fb + 5af41d0 commit 3971cf1

File tree

5 files changed

+18
-9
lines changed

5 files changed

+18
-9
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ Modified Compiler Flags
231231
f3 *c = (f3 *)x;
232232
}
233233
234+
- Carved out ``-Wformat`` warning about scoped enums into a subwarning and
235+
make it controlled by ``-Wformat-pedantic``. Fixes #GH88595.
234236

235237
Removed Compiler Flags
236238
-------------------------

clang/lib/Sema/SemaChecking.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12879,10 +12879,15 @@ CheckPrintfHandler::checkFormatExpr(const analyze_printf::PrintfSpecifier &FS,
1287912879
// In this case, the expression could be printed using a different
1288012880
// specifier, but we've decided that the specifier is probably correct
1288112881
// and we should cast instead. Just use the normal warning message.
12882+
12883+
unsigned Diag =
12884+
IsScopedEnum
12885+
? diag::warn_format_conversion_argument_type_mismatch_pedantic
12886+
: diag::warn_format_conversion_argument_type_mismatch;
12887+
1288212888
EmitFormatDiagnostic(
12883-
S.PDiag(diag::warn_format_conversion_argument_type_mismatch)
12884-
<< AT.getRepresentativeTypeName(S.Context) << ExprTy << IsEnum
12885-
<< E->getSourceRange(),
12889+
S.PDiag(Diag) << AT.getRepresentativeTypeName(S.Context) << ExprTy
12890+
<< IsEnum << E->getSourceRange(),
1288612891
E->getBeginLoc(), /*IsStringLocation*/ false, SpecRange, Hints);
1288712892
}
1288812893
}

clang/test/FixIt/format-darwin-enum-class.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -verify -Wformat %s
2-
// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -fdiagnostics-parseable-fixits -Wformat %s 2>&1 | FileCheck %s
1+
// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -verify -Wformat-pedantic %s
2+
// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -fdiagnostics-parseable-fixits -Wformat-pedantic %s 2>&1 | FileCheck %s
33

44
extern "C" int printf(const char * restrict, ...);
55

clang/test/FixIt/format.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
// RUN: %clang_cc1 -fsyntax-only -verify -Wformat %s
2-
// RUN: %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits -Wformat %s 2>&1 | FileCheck %s
1+
// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-pedantic %s
2+
// RUN: %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits -Wformat-pedantic %s 2>&1 | FileCheck %s
3+
// RUN: %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits -Wformat %s -verify=okay
4+
// okay-no-diagnostics
35

46
extern "C" int printf(const char *, ...);
57
#define LOG(...) printf(__VA_ARGS__)

clang/test/SemaCXX/format-strings.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -Wformat-non-iso -fblocks %s
1+
// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -Wformat-non-iso -Wformat-pedantic -fblocks %s
22
// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -Wformat-non-iso -fblocks -std=c++98 %s
3-
// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -Wformat-non-iso -fblocks -std=c++11 %s
3+
// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -Wformat-non-iso -Wformat-pedantic -fblocks -std=c++11 %s
44

55
#include <stdarg.h>
66

0 commit comments

Comments
 (0)