diff mbox

fix class enum lookup

Message ID 555BE9B6.1060307@acm.org
State New
Headers show

Commit Message

Nathan Sidwell May 20, 2015, 1:56 a.m. UTC
I've committed this obvious patch for 65954.  We failed to issue a diagnostic 
for a failed class enum lookup, and returned NULL, rather than error_mark_node, 
leading to a seg fault.

booted & tested on x86_64-linux.

nathan
diff mbox

Patch

2015-05-19  Nathan sidwell  <nathan@acm.org>

	cp/
	PR c++/65954
	* typeck.c (finish_class_member_access_expr): Diagnose failed
	lookup of enum class member.

	testsuite/
	* g++.dg/cpp0x/pr65954.C: New.

Index: cp/typeck.c
===================================================================
--- cp/typeck.c	(revision 223414)
+++ cp/typeck.c	(working copy)
@@ -2731,6 +2731,14 @@  finish_class_member_access_expr (tree ob
 		  return error_mark_node;
 		}
 	      tree val = lookup_enumerator (scope, name);
+	      if (!val)
+		{
+		  if (complain & tf_error)
+		    error ("%qD is not a member of %qD",
+			   name, scope);
+		  return error_mark_node;
+		}
+	      
 	      if (TREE_SIDE_EFFECTS (object))
 		val = build2 (COMPOUND_EXPR, TREE_TYPE (val), object, val);
 	      return val;
Index: testsuite/g++.dg/cpp0x/pr65954.C
===================================================================
--- testsuite/g++.dg/cpp0x/pr65954.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/pr65954.C	(working copy)
@@ -0,0 +1,12 @@ 
+// { dg-do compile { target c++11 } }
+
+struct Shape {
+  enum class Type
+  { Circle, Square };
+};
+
+
+void Foo (Shape &shape)
+{
+  +shape.Type::NOPE; // { dg-error "is not a member of" }
+}