]> granicus.if.org Git - clang/commitdiff
MS extensions: Properly diagnose address of MS property decl
authorReid Kleckner <reid@kleckner.net>
Tue, 24 Feb 2015 20:29:40 +0000 (20:29 +0000)
committerReid Kleckner <reid@kleckner.net>
Tue, 24 Feb 2015 20:29:40 +0000 (20:29 +0000)
Summary: Fixes PR22671.

Reviewers: rsmith

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D7863

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@230362 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ExprClassification.cpp
lib/Sema/SemaExpr.cpp
test/SemaCXX/MicrosoftExtensions.cpp

index 933ea97fa2babfe50e96be6e19968e7b2020c1bf..124b4675ca80f3c3976c5e95e89241aa58b759b8 100644 (file)
@@ -418,9 +418,10 @@ static Cl::Kinds ClassifyDecl(ASTContext &Ctx, const Decl *D) {
     islvalue = NTTParm->getType()->isReferenceType();
   else
     islvalue = isa<VarDecl>(D) || isa<FieldDecl>(D) ||
-         isa<IndirectFieldDecl>(D) ||
-      (Ctx.getLangOpts().CPlusPlus &&
-        (isa<FunctionDecl>(D) || isa<FunctionTemplateDecl>(D)));
+               isa<IndirectFieldDecl>(D) ||
+               (Ctx.getLangOpts().CPlusPlus &&
+                (isa<FunctionDecl>(D) || isa<MSPropertyDecl>(D) ||
+                 isa<FunctionTemplateDecl>(D)));
 
   return islvalue ? Cl::CL_LValue : Cl::CL_PRValue;
 }
index 4b807c1058135e97593d23c6498541c8878cd1f9..90f504658267e6b5319c5c129c0abfd6ec40b639 100644 (file)
@@ -9352,6 +9352,8 @@ QualType Sema::CheckAddressOfOperand(ExprResult &OrigOp, SourceLocation OpLoc) {
           !getLangOpts().CPlusPlus) {
         AddressOfError = AO_Register_Variable;
       }
+    } else if (isa<MSPropertyDecl>(dcl)) {
+      AddressOfError = AO_Property_Expansion;
     } else if (isa<FunctionTemplateDecl>(dcl)) {
       return Context.OverloadTy;
     } else if (isa<FieldDecl>(dcl) || isa<IndirectFieldDecl>(dcl)) {
index 57d6f0d6bef2bc0a08545e2dde225727a58439b7..db5e4586daf5ae34aff06fcbcf64e7746eb4bc02 100644 (file)
@@ -344,6 +344,18 @@ struct StructWithUnnamedMember {
   __declspec(property(get=GetV)) int : 10; // expected-error {{anonymous property is not supported}}
 };
 
+struct MSPropertyClass {
+  int get() { return 42; }
+  int __declspec(property(get = get)) n;
+};
+
+int *f(MSPropertyClass &x) {
+  return &x.n; // expected-error {{address of property expression requested}}
+}
+int MSPropertyClass::*g() {
+  return &MSPropertyClass::n; // expected-error {{address of property expression requested}}
+}
+
 namespace rdar14250378 {
   class Bar {};