r233387 - [Sema] Factor diags with %plural. No functionality change intended.
Benjamin Kramer
benny.kra at googlemail.com
Fri Mar 27 10:23:15 PDT 2015
Author: d0k
Date: Fri Mar 27 12:23:14 2015
New Revision: 233387
URL: http://llvm.org/viewvc/llvm-project?rev=233387&view=rev
Log:
[Sema] Factor diags with %plural. No functionality change intended.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaStmt.cpp
cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=233387&r1=233386&r2=233387&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Mar 27 12:23:14 2015
@@ -3801,34 +3801,14 @@ def note_template_parameter_pack_here :
"previous %select{template type|non-type template|template template}0 "
"parameter%select{| pack}1 declared here">;
-def err_unexpanded_parameter_pack_0 : Error<
+def err_unexpanded_parameter_pack : Error<
"%select{expression|base type|declaration type|data member type|bit-field "
"size|static assertion|fixed underlying type|enumerator value|"
"using declaration|friend declaration|qualifier|initializer|default argument|"
"non-type template parameter type|exception type|partial specialization|"
- "__if_exists name|__if_not_exists name|lambda|block}0 "
- "contains an unexpanded parameter pack">;
-def err_unexpanded_parameter_pack_1 : Error<
- "%select{expression|base type|declaration type|data member type|bit-field "
- "size|static assertion|fixed underlying type|enumerator value|"
- "using declaration|friend declaration|qualifier|initializer|default argument|"
- "non-type template parameter type|exception type|partial specialization|"
- "__if_exists name|__if_not_exists name|lambda|block}0 "
- "contains unexpanded parameter pack %1">;
-def err_unexpanded_parameter_pack_2 : Error<
- "%select{expression|base type|declaration type|data member type|bit-field "
- "size|static assertion|fixed underlying type|enumerator value|"
- "using declaration|friend declaration|qualifier|initializer|default argument|"
- "non-type template parameter type|exception type|partial specialization|"
- "__if_exists name|__if_not_exists name|lambda|block}0 "
- "contains unexpanded parameter packs %1 and %2">;
-def err_unexpanded_parameter_pack_3_or_more : Error<
- "%select{expression|base type|declaration type|data member type|bit-field "
- "size|static assertion|fixed underlying type|enumerator value|"
- "using declaration|friend declaration|qualifier|initializer|default argument|"
- "non-type template parameter type|exception type|partial specialization|"
- "__if_exists name|__if_not_exists name|lambda|block}0 "
- "contains unexpanded parameter packs %1, %2, ...">;
+ "__if_exists name|__if_not_exists name|lambda|block}0 contains"
+ "%plural{0: an|:}1 unexpanded parameter pack"
+ "%plural{0:|1: %2|2:s %2 and %3|:s %2, %3, ...}1">;
def err_pack_expansion_without_parameter_packs : Error<
"pack expansion does not contain any unexpanded parameter packs">;
@@ -6878,29 +6858,18 @@ def warn_case_empty_range : Warning<"emp
def warn_missing_case_for_condition :
Warning<"no case matching constant switch condition '%0'">;
-def warn_def_missing_case1 : Warning<
- "enumeration value %0 not explicitly handled in switch">,
- InGroup<SwitchEnum>, DefaultIgnore;
-def warn_def_missing_case2 : Warning<
- "enumeration values %0 and %1 not explicitly handled in switch">,
- InGroup<SwitchEnum>, DefaultIgnore;
-def warn_def_missing_case3 : Warning<
- "enumeration values %0, %1, and %2 not explicitly handled in switch">,
- InGroup<SwitchEnum>, DefaultIgnore;
-def warn_def_missing_cases : Warning<
- "%0 enumeration values not explicitly handled in switch: %1, %2, %3...">,
+def warn_def_missing_case : Warning<"%plural{"
+ "1:enumeration value %1 not explicitly handled in switch|"
+ "2:enumeration values %1 and %2 not explicitly handled in switch|"
+ "3:enumeration values %1, %2, and %3 not explicitly handled in switch|"
+ ":%0 enumeration values not explicitly handled in switch: %1, %2, %3...}0">,
InGroup<SwitchEnum>, DefaultIgnore;
-def warn_missing_case1 : Warning<"enumeration value %0 not handled in switch">,
- InGroup<Switch>;
-def warn_missing_case2 : Warning<
- "enumeration values %0 and %1 not handled in switch">,
- InGroup<Switch>;
-def warn_missing_case3 : Warning<
- "enumeration values %0, %1, and %2 not handled in switch">,
- InGroup<Switch>;
-def warn_missing_cases : Warning<
- "%0 enumeration values not handled in switch: %1, %2, %3...">,
+def warn_missing_case : Warning<"%plural{"
+ "1:enumeration value %1 not handled in switch|"
+ "2:enumeration values %1 and %2 not handled in switch|"
+ "3:enumeration values %1, %2, and %3 not handled in switch|"
+ ":%0 enumeration values not handled in switch: %1, %2, %3...}0">,
InGroup<Switch>;
def warn_unannotated_fallthrough : Warning<
Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=233387&r1=233386&r2=233387&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Fri Mar 27 12:23:14 2015
@@ -1133,29 +1133,15 @@ Sema::ActOnFinishSwitchStmt(SourceLocati
Diag(TheDefaultStmt->getDefaultLoc(), diag::warn_unreachable_default);
// Produce a nice diagnostic if multiple values aren't handled.
- switch (UnhandledNames.size()) {
- case 0: break;
- case 1:
- Diag(CondExpr->getExprLoc(), TheDefaultStmt
- ? diag::warn_def_missing_case1 : diag::warn_missing_case1)
- << UnhandledNames[0];
- break;
- case 2:
- Diag(CondExpr->getExprLoc(), TheDefaultStmt
- ? diag::warn_def_missing_case2 : diag::warn_missing_case2)
- << UnhandledNames[0] << UnhandledNames[1];
- break;
- case 3:
- Diag(CondExpr->getExprLoc(), TheDefaultStmt
- ? diag::warn_def_missing_case3 : diag::warn_missing_case3)
- << UnhandledNames[0] << UnhandledNames[1] << UnhandledNames[2];
- break;
- default:
- Diag(CondExpr->getExprLoc(), TheDefaultStmt
- ? diag::warn_def_missing_cases : diag::warn_missing_cases)
- << (unsigned)UnhandledNames.size()
- << UnhandledNames[0] << UnhandledNames[1] << UnhandledNames[2];
- break;
+ if (!UnhandledNames.empty()) {
+ DiagnosticBuilder DB = Diag(CondExpr->getExprLoc(),
+ TheDefaultStmt ? diag::warn_def_missing_case
+ : diag::warn_missing_case)
+ << (int)UnhandledNames.size();
+
+ for (size_t I = 0, E = std::min(UnhandledNames.size(), (size_t)3);
+ I != E; ++I)
+ DB << UnhandledNames[I];
}
if (!hasCasesNotInSwitch)
Modified: cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp?rev=233387&r1=233386&r2=233387&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp Fri Mar 27 12:23:14 2015
@@ -251,15 +251,10 @@ Sema::DiagnoseUnexpandedParameterPacks(S
Locations.push_back(Unexpanded[I].second);
}
- DiagnosticBuilder DB
- = Names.size() == 0? Diag(Loc, diag::err_unexpanded_parameter_pack_0)
- << (int)UPPC
- : Names.size() == 1? Diag(Loc, diag::err_unexpanded_parameter_pack_1)
- << (int)UPPC << Names[0]
- : Names.size() == 2? Diag(Loc, diag::err_unexpanded_parameter_pack_2)
- << (int)UPPC << Names[0] << Names[1]
- : Diag(Loc, diag::err_unexpanded_parameter_pack_3_or_more)
- << (int)UPPC << Names[0] << Names[1];
+ DiagnosticBuilder DB = Diag(Loc, diag::err_unexpanded_parameter_pack)
+ << (int)UPPC << (int)Names.size();
+ for (size_t I = 0, E = std::min(Names.size(), (size_t)2); I != E; ++I)
+ DB << Names[I];
for (unsigned I = 0, N = Locations.size(); I != N; ++I)
DB << SourceRange(Locations[I]);
More information about the cfe-commits
mailing list