From 5b330db270bedc7f617cb2b06d0b531aeca2c949 Mon Sep 17 00:00:00 2001 From: DeLesley Hutchins Date: Sat, 25 Feb 2012 00:11:55 +0000 Subject: [PATCH] Bugfix: bogus warning -- "invalid use of non-static data member", when a class is forward declared, and the reference to the data member in question does not occur within a method body. llvm-svn: 151413 --- clang/lib/Sema/SemaExprMember.cpp | 3 ++- clang/test/SemaCXX/cxx0x-class.cpp | 11 +++++++++++ clang/test/SemaCXX/warn-thread-safety-analysis.cpp | 14 ++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaExprMember.cpp b/clang/lib/Sema/SemaExprMember.cpp index 92cf619d92aa..54296942d0d4 100644 --- a/clang/lib/Sema/SemaExprMember.cpp +++ b/clang/lib/Sema/SemaExprMember.cpp @@ -173,7 +173,8 @@ static IMAKind ClassifyImplicitMemberAccess(Sema &SemaRef, // ...if C is not X or a base class of X, the class member access expression // is ill-formed. if (R.getNamingClass() && - contextClass != R.getNamingClass()->getCanonicalDecl() && + contextClass->getCanonicalDecl() != + R.getNamingClass()->getCanonicalDecl() && contextClass->isProvablyNotDerivedFrom(R.getNamingClass())) return (hasNonInstance ? IMA_Mixed_Unrelated : IMA_Error_Unrelated); diff --git a/clang/test/SemaCXX/cxx0x-class.cpp b/clang/test/SemaCXX/cxx0x-class.cpp index d5590c5e22de..41b0a5ce9589 100644 --- a/clang/test/SemaCXX/cxx0x-class.cpp +++ b/clang/test/SemaCXX/cxx0x-class.cpp @@ -26,3 +26,14 @@ namespace rdar8367341 { static constexpr float y2 = foo(); // expected-error {{must be initialized by a constant expression}} expected-note {{non-constexpr function 'foo'}} }; } + + +namespace Foo { + // Regression test -- forward declaration of Foo should not cause error about + // nonstatic data member. + class Foo; + class Foo { + int x; + int y = x; + }; +} diff --git a/clang/test/SemaCXX/warn-thread-safety-analysis.cpp b/clang/test/SemaCXX/warn-thread-safety-analysis.cpp index 8bbaf0398fae..a7c1c0026854 100644 --- a/clang/test/SemaCXX/warn-thread-safety-analysis.cpp +++ b/clang/test/SemaCXX/warn-thread-safety-analysis.cpp @@ -2100,3 +2100,17 @@ public: } // end namespace SelfLockingTest +namespace InvalidNonstatic { + +// Forward decl here causes bogus "invalid use of non-static data member" +// on reference to mutex_ in guarded_by attribute. +class Foo; + +class Foo { + Mutex* mutex_; + + int foo __attribute__((guarded_by(mutex_))); +}; + +} // end namespace InvalidNonStatic +