From c05006fda51658dc0a2fd551aeceaf90605bfc41 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Wed, 12 Mar 2014 23:36:42 +0000 Subject: [PATCH] Only allow streaming exactly type 'bool' to a DiagnosticBuilder, not anything that implicitly converts to 'bool' (such as pointers, and the first operand of ?:). Clean up issues found by this. Patch by Stephan Tolksdorf! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203735 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/Diagnostic.h | 9 +++++++-- lib/Driver/Driver.cpp | 4 ++-- lib/Lex/ModuleMap.cpp | 3 ++- lib/Sema/SemaDeclCXX.cpp | 3 +-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/include/clang/Basic/Diagnostic.h b/include/clang/Basic/Diagnostic.h index ab4f39fe56..6082ec8b1f 100644 --- a/include/clang/Basic/Diagnostic.h +++ b/include/clang/Basic/Diagnostic.h @@ -1014,8 +1014,13 @@ inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, int I) { return DB; } -inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, - bool I) { +// We use enable_if here to prevent that this overload is selected for +// pointers or other arguments that are implicitly convertible to bool. +template +inline +typename std::enable_if::value, + const DiagnosticBuilder &>::type +operator<<(const DiagnosticBuilder &DB, T I) { DB.AddTaggedVal(I, DiagnosticsEngine::ak_sint); return DB; } diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index fa7e16c41e..c318b60a93 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -1192,13 +1192,13 @@ void Driver::BuildActions(const ToolChain &TC, DerivedArgList &Args, Diag(clang::diag::warn_drv_preprocessed_input_file_unused) << InputArg->getAsString(Args) << !!FinalPhaseArg - << FinalPhaseArg ? FinalPhaseArg->getOption().getName() : ""; + << (FinalPhaseArg ? FinalPhaseArg->getOption().getName() : ""); else Diag(clang::diag::warn_drv_input_file_unused) << InputArg->getAsString(Args) << getPhaseName(InitialPhase) << !!FinalPhaseArg - << FinalPhaseArg ? FinalPhaseArg->getOption().getName() : ""; + << (FinalPhaseArg ? FinalPhaseArg->getOption().getName() : ""); continue; } diff --git a/lib/Lex/ModuleMap.cpp b/lib/Lex/ModuleMap.cpp index beb0bcbbd3..d5e8af95fe 100644 --- a/lib/Lex/ModuleMap.cpp +++ b/lib/Lex/ModuleMap.cpp @@ -1282,7 +1282,8 @@ void ModuleMapParser::parseModuleDecl() { if (ActiveModule) { Diags.Report(Id[I].second, diag::err_mmap_missing_module_qualified) - << Id[I].first << ActiveModule->getTopLevelModule(); + << Id[I].first + << ActiveModule->getTopLevelModule()->getFullModuleName(); } else { Diags.Report(Id[I].second, diag::err_mmap_expected_module_name); } diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 027fd6f309..c75bac5e8c 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -6564,8 +6564,7 @@ static void DiagnoseNamespaceInlineMismatch(Sema &S, SourceLocation KeywordLoc, S.Diag(Loc, diag::warn_inline_namespace_reopened_noninline) << FixItHint::CreateInsertion(KeywordLoc, "inline "); else - S.Diag(Loc, diag::err_inline_namespace_mismatch) - << IsInline; + S.Diag(Loc, diag::err_inline_namespace_mismatch) << *IsInline; S.Diag(PrevNS->getLocation(), diag::note_previous_definition); *IsInline = PrevNS->isInline(); -- 2.40.0