From 9aa8b55d10234892c8427f23bca13cb2cc8e313a Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Wed, 10 Dec 2008 21:26:49 +0000 Subject: [PATCH] Fix PR clang/3175: CheckAddressOfOperand does not handle references to class vars llvm-svn: 60849 --- clang/lib/Sema/SemaExpr.cpp | 5 ++++- clang/test/SemaCXX/address-of.cpp | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 clang/test/SemaCXX/address-of.cpp diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index a36bcf588065..8cbbca3fbf0b 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -2876,8 +2876,11 @@ QualType Sema::CheckAddressOfOperand(Expr *op, SourceLocation OpLoc) { << "register variable" << op->getSourceRange(); return QualType(); } - } else if (isa(dcl)) + } else if (isa(dcl)) { return Context.OverloadTy; + } else if (isa(dcl)) { + // Okay: we can take the address of a field. + } else assert(0 && "Unknown/unexpected decl type"); } diff --git a/clang/test/SemaCXX/address-of.cpp b/clang/test/SemaCXX/address-of.cpp new file mode 100644 index 000000000000..5451f32688b4 --- /dev/null +++ b/clang/test/SemaCXX/address-of.cpp @@ -0,0 +1,31 @@ +// RUN: clang -fsyntax-only -verify %S +// PR clang/3175 + +void bar(int*); + +class c { + int var; + static int svar; + void foo() { + bar(&var); + bar(&svar); + } + + static void wibble() { + bar(&var); // expected-error{{invalid use of member 'var' in static member function}} + bar(&svar); + } +}; + +enum E { + Enumerator +}; + +void test() { + (void)&Enumerator; // expected-error{{address expression must be an lvalue or a function designator}} +} + +template +void test2() { + (void)&N; // expected-error{{address expression must be an lvalue or a function designator}} +}