Skip to content

Commit 73ed215

Browse files
authored
Carving out -Wformat warning about scoped enums into a subwarning (llvm#88595)
Make it part of -Wformat-pedantic. Fixes llvm#81647
1 parent 7c20576 commit 73ed215

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
@@ -251,6 +251,8 @@ Modified Compiler Flags
251251
f3 *c = (f3 *)x;
252252
}
253253
254+
- Carved out ``-Wformat`` warning about scoped enums into a subwarning and
255+
make it controlled by ``-Wformat-pedantic``. Fixes #GH88595.
254256

255257
Removed Compiler Flags
256258
-------------------------

clang/lib/Sema/SemaChecking.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12779,10 +12779,15 @@ CheckPrintfHandler::checkFormatExpr(const analyze_printf::PrintfSpecifier &FS,
1277912779
// In this case, the expression could be printed using a different
1278012780
// specifier, but we've decided that the specifier is probably correct
1278112781
// and we should cast instead. Just use the normal warning message.
12782+
12783+
unsigned Diag =
12784+
IsScopedEnum
12785+
? diag::warn_format_conversion_argument_type_mismatch_pedantic
12786+
: diag::warn_format_conversion_argument_type_mismatch;
12787+
1278212788
EmitFormatDiagnostic(
12783-
S.PDiag(diag::warn_format_conversion_argument_type_mismatch)
12784-
<< AT.getRepresentativeTypeName(S.Context) << ExprTy << IsEnum
12785-
<< E->getSourceRange(),
12789+
S.PDiag(Diag) << AT.getRepresentativeTypeName(S.Context) << ExprTy
12790+
<< IsEnum << E->getSourceRange(),
1278612791
E->getBeginLoc(), /*IsStringLocation*/ false, SpecRange, Hints);
1278712792
}
1278812793
}

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)