r174020 - Fix ODR-use of a MemberExpr to check before marking a pure function used. Remove
Nick Lewycky
nicholas at mxc.ca
Wed Jan 30 17:34:32 PST 2013
Author: nicholas
Date: Wed Jan 30 19:34:31 2013
New Revision: 174020
URL: http://llvm.org/viewvc/llvm-project?rev=174020&view=rev
Log:
Fix ODR-use of a MemberExpr to check before marking a pure function used. Remove
a workaround for this bug from the -Wundefined-internals warning.
Modified:
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/SemaCXX/undefined-internal.cpp
Modified: cfe/trunk/lib/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=174020&r1=174019&r2=174020&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Wed Jan 30 19:34:31 2013
@@ -396,7 +396,7 @@ static void checkUndefinedInternals(Sema
if (decl->hasAttr<WeakRefAttr>()) continue;
if (FunctionDecl *fn = dyn_cast<FunctionDecl>(decl)) {
- if (fn->isPure() || fn->hasBody())
+ if (fn->isDefined())
continue;
} else {
if (cast<VarDecl>(decl)->hasDefinition() != VarDecl::DeclarationOnly)
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=174020&r1=174019&r2=174020&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Jan 30 19:34:31 2013
@@ -10506,8 +10506,7 @@ void Sema::MarkFunctionReferenced(Source
}
// Keep track of used but undefined functions.
- if (!Func->isPure() && !Func->hasBody() &&
- Func->getLinkage() != ExternalLinkage) {
+ if (!Func->isDefined() && Func->getLinkage() != ExternalLinkage) {
SourceLocation &old = UndefinedInternals[Func->getCanonicalDecl()];
if (old.isInvalid()) old = Loc;
}
@@ -11167,6 +11166,17 @@ void Sema::MarkDeclRefReferenced(DeclRef
/// \brief Perform reference-marking and odr-use handling for a MemberExpr.
void Sema::MarkMemberReferenced(MemberExpr *E) {
+ // C++11 [basic.def.odr]p2
+ // A non-overloaded function whose name appears as a potentially-evaluated
+ // expression or a member of a set of candidate functions, if selected by
+ // overload resolution when referred to from a potentially-evaluated
+ // expression, is odr-used, unless it is a pure virtual function and its
+ // name is not explicitly qualified.
+ if (!E->hasQualifier()) {
+ if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(E->getMemberDecl()))
+ if (Method->isPure())
+ return;
+ }
MarkExprReferenced(*this, E->getMemberLoc(), E->getMemberDecl(), E);
}
Modified: cfe/trunk/test/SemaCXX/undefined-internal.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/undefined-internal.cpp?rev=174020&r1=174019&r2=174020&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/undefined-internal.cpp (original)
+++ cfe/trunk/test/SemaCXX/undefined-internal.cpp Wed Jan 30 19:34:31 2013
@@ -199,3 +199,16 @@ namespace test8 {
}
} *A;
}
+
+namespace test9 {
+ namespace {
+ struct X {
+ virtual void notused() = 0;
+ virtual void used() = 0; // expected-warning {{function 'test9::<anonymous namespace>::X::used' has internal linkage but is not defined}}
+ };
+ }
+ void test(X &x) {
+ x.notused();
+ x.X::used(); // expected-note {{used here}}
+ }
+}
More information about the cfe-commits
mailing list