[PATCH] D42969: [Sema] Fix decltype of static data members

2018-02-09 Thread Roger Ferrer Ibanez via Phabricator via cfe-commits
rogfer01 accepted this revision.
rogfer01 added a comment.
This revision is now accepted and ready to land.

This LGTM. Thanks for fixing this.

Wait a couple of days before committing in case there are other comments.


https://reviews.llvm.org/D42969



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42969: [Sema] Fix decltype of static data members

2018-02-14 Thread Mikhail Maltsev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC325117: [Sema] Fix decltype of static data members (authored 
by miyuki, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D42969

Files:
  lib/Sema/SemaType.cpp
  test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.simple/p4-cxx0x.cpp


Index: test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.simple/p4-cxx0x.cpp
===
--- test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.simple/p4-cxx0x.cpp
+++ test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.simple/p4-cxx0x.cpp
@@ -12,13 +12,18 @@
 
 const int&& foo();
 int i;
-struct A { double x; };
+struct A {
+  double x;
+  static int y;
+};
 const A* a = new A();
 
 static_assert(is_same::value, "");
 static_assert(is_same::value, "");
 static_assert(is_samex), double>::value, "");
 static_assert(is_samex)), const double&>::value, "");
+static_assert(is_samey), int>::value, "");
+static_assert(is_samey)), int&>::value, "");
 static_assert(is_same(i)), int&&>::value, "");
 
 int f0(int); // expected-note{{possible target}}
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -7868,8 +7868,9 @@
 if (const ValueDecl *VD = dyn_cast(DRE->getDecl()))
   return VD->getType();
   } else if (const MemberExpr *ME = dyn_cast(E)) {
-if (const FieldDecl *FD = dyn_cast(ME->getMemberDecl()))
-  return FD->getType();
+if (const ValueDecl *VD = ME->getMemberDecl())
+  if (isa(VD) || isa(VD))
+return VD->getType();
   } else if (const ObjCIvarRefExpr *IR = dyn_cast(E)) {
 return IR->getDecl()->getType();
   } else if (const ObjCPropertyRefExpr *PR = dyn_cast(E)) 
{


Index: test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.simple/p4-cxx0x.cpp
===
--- test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.simple/p4-cxx0x.cpp
+++ test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.simple/p4-cxx0x.cpp
@@ -12,13 +12,18 @@
 
 const int&& foo();
 int i;
-struct A { double x; };
+struct A {
+  double x;
+  static int y;
+};
 const A* a = new A();
 
 static_assert(is_same::value, "");
 static_assert(is_same::value, "");
 static_assert(is_samex), double>::value, "");
 static_assert(is_samex)), const double&>::value, "");
+static_assert(is_samey), int>::value, "");
+static_assert(is_samey)), int&>::value, "");
 static_assert(is_same(i)), int&&>::value, "");
 
 int f0(int); // expected-note{{possible target}}
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -7868,8 +7868,9 @@
 if (const ValueDecl *VD = dyn_cast(DRE->getDecl()))
   return VD->getType();
   } else if (const MemberExpr *ME = dyn_cast(E)) {
-if (const FieldDecl *FD = dyn_cast(ME->getMemberDecl()))
-  return FD->getType();
+if (const ValueDecl *VD = ME->getMemberDecl())
+  if (isa(VD) || isa(VD))
+return VD->getType();
   } else if (const ObjCIvarRefExpr *IR = dyn_cast(E)) {
 return IR->getDecl()->getType();
   } else if (const ObjCPropertyRefExpr *PR = dyn_cast(E)) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42969: [Sema] Fix decltype of static data members

2018-02-06 Thread Mikhail Maltsev via Phabricator via cfe-commits
miyuki created this revision.
miyuki added reviewers: faisalv, rsmith.
miyuki edited the summary of this revision.

According to the C++11 standard [dcl.type.simple]p4:

  The type denoted by decltype(e) is defined as follows:
  - if e is an unparenthesized id-expression or an unparenthesized
class member access (5.2.5), decltype(e) is the type of the entity
named by e.


Currently Clang handles the 'member access' case incorrectly for
static data members (decltype returns T& instead of T). This patch
fixes the issue.


https://reviews.llvm.org/D42969

Files:
  lib/Sema/SemaType.cpp
  test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.simple/p4-cxx0x.cpp


Index: test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.simple/p4-cxx0x.cpp
===
--- test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.simple/p4-cxx0x.cpp
+++ test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.simple/p4-cxx0x.cpp
@@ -12,13 +12,18 @@
 
 const int&& foo();
 int i;
-struct A { double x; };
+struct A {
+  double x;
+  static int y;
+};
 const A* a = new A();
 
 static_assert(is_same::value, "");
 static_assert(is_same::value, "");
 static_assert(is_samex), double>::value, "");
 static_assert(is_samex)), const double&>::value, "");
+static_assert(is_samey), int>::value, "");
+static_assert(is_samey)), int&>::value, "");
 static_assert(is_same(i)), int&&>::value, "");
 
 int f0(int); // expected-note{{possible target}}
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -7859,8 +7859,9 @@
 if (const ValueDecl *VD = dyn_cast(DRE->getDecl()))
   return VD->getType();
   } else if (const MemberExpr *ME = dyn_cast(E)) {
-if (const FieldDecl *FD = dyn_cast(ME->getMemberDecl()))
-  return FD->getType();
+if (const ValueDecl *VD = ME->getMemberDecl())
+  if (isa(VD) || isa(VD))
+return VD->getType();
   } else if (const ObjCIvarRefExpr *IR = dyn_cast(E)) {
 return IR->getDecl()->getType();
   } else if (const ObjCPropertyRefExpr *PR = dyn_cast(E)) 
{


Index: test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.simple/p4-cxx0x.cpp
===
--- test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.simple/p4-cxx0x.cpp
+++ test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.simple/p4-cxx0x.cpp
@@ -12,13 +12,18 @@
 
 const int&& foo();
 int i;
-struct A { double x; };
+struct A {
+  double x;
+  static int y;
+};
 const A* a = new A();
 
 static_assert(is_same::value, "");
 static_assert(is_same::value, "");
 static_assert(is_samex), double>::value, "");
 static_assert(is_samex)), const double&>::value, "");
+static_assert(is_samey), int>::value, "");
+static_assert(is_samey)), int&>::value, "");
 static_assert(is_same(i)), int&&>::value, "");
 
 int f0(int); // expected-note{{possible target}}
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -7859,8 +7859,9 @@
 if (const ValueDecl *VD = dyn_cast(DRE->getDecl()))
   return VD->getType();
   } else if (const MemberExpr *ME = dyn_cast(E)) {
-if (const FieldDecl *FD = dyn_cast(ME->getMemberDecl()))
-  return FD->getType();
+if (const ValueDecl *VD = ME->getMemberDecl())
+  if (isa(VD) || isa(VD))
+return VD->getType();
   } else if (const ObjCIvarRefExpr *IR = dyn_cast(E)) {
 return IR->getDecl()->getType();
   } else if (const ObjCPropertyRefExpr *PR = dyn_cast(E)) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits