r178923 - When -Woverloaded-virtual is triggered, call HandleFunctionTypeMismatch to add
Richard Trieu
rtrieu at google.com
Fri Apr 5 16:02:24 PDT 2013
Author: rtrieu
Date: Fri Apr 5 18:02:24 2013
New Revision: 178923
URL: http://llvm.org/viewvc/llvm-project?rev=178923&view=rev
Log:
When -Woverloaded-virtual is triggered, call HandleFunctionTypeMismatch to add
more information to the notes. This information is already present on other
diagnostic messages that involves overloads.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/SemaCXX/warn-overloaded-virtual.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=178923&r1=178922&r2=178923&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Apr 5 18:02:24 2013
@@ -4686,7 +4686,16 @@ def warn_overloaded_virtual : Warning<
"%q0 hides overloaded virtual %select{function|functions}1">,
InGroup<OverloadedVirtual>, DefaultIgnore;
def note_hidden_overloaded_virtual_declared_here : Note<
- "hidden overloaded virtual function %q0 declared here">;
+ "hidden overloaded virtual function %q0 declared here"
+ "%select{|: different classes%diff{ ($ vs $)|}2,3"
+ "|: different number of parameters (%2 vs %3)"
+ "|: type mismatch at %ordinal2 parameter%diff{ ($ vs $)|}3,4"
+ "|: different return type%diff{ ($ vs $)|}2,3"
+ "|: different qualifiers ("
+ "%select{none|const|restrict|const and restrict|volatile|const and volatile|"
+ "volatile and restrict|const, volatile, and restrict}2 vs "
+ "%select{none|const|restrict|const and restrict|volatile|const and volatile|"
+ "volatile and restrict|const, volatile, and restrict}3)}1">;
def warn_using_directive_in_header : Warning<
"using namespace directive in global context in header">,
InGroup<HeaderHygiene>, DefaultIgnore;
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=178923&r1=178922&r2=178923&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Fri Apr 5 18:02:24 2013
@@ -5409,8 +5409,10 @@ void Sema::DiagnoseHiddenVirtualMethods(
for (unsigned i = 0, e = Data.OverloadedMethods.size(); i != e; ++i) {
CXXMethodDecl *overloadedMD = Data.OverloadedMethods[i];
- Diag(overloadedMD->getLocation(),
+ PartialDiagnostic PD = PDiag(
diag::note_hidden_overloaded_virtual_declared_here) << overloadedMD;
+ HandleFunctionTypeMismatch(PD, MD->getType(), overloadedMD->getType());
+ Diag(overloadedMD->getLocation(), PD);
}
}
}
Modified: cfe/trunk/test/SemaCXX/warn-overloaded-virtual.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-overloaded-virtual.cpp?rev=178923&r1=178922&r2=178923&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-overloaded-virtual.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-overloaded-virtual.cpp Fri Apr 5 18:02:24 2013
@@ -120,3 +120,21 @@ struct MostDerived: Derived3, Derived2 {
void func();
};
}
+
+namespace {
+ class A {
+ virtual int foo(bool) const;
+ // expected-note at -1{{type mismatch at 1st parameter ('bool' vs 'int')}}
+ virtual int foo(int, int) const;
+ // expected-note at -1{{different number of parameters (2 vs 1)}}
+ virtual int foo(int*) const;
+ // expected-note at -1{{type mismatch at 1st parameter ('int *' vs 'int')}}
+ virtual int foo(int) volatile;
+ // expected-note at -1{{different qualifiers (volatile vs const)}}
+ };
+
+ class B : public A {
+ virtual int foo(int) const;
+ // expected-warning at -1{{hides overloaded virtual functions}}
+ };
+}
More information about the cfe-commits
mailing list