diff mbox series

[C++] cp_expr tweak and delete unused enumerations

Message ID c612e36d-75db-22ac-14c1-e6bbefd18e9a@acm.org
State New
Headers show
Series [C++] cp_expr tweak and delete unused enumerations | expand

Commit Message

Nathan Sidwell Oct. 12, 2017, 6:56 p.m. UTC
The cp_expr class doesn't have a const-qualified operator * accessor. 
This leaves one with a confusing error message if one ever tries to 
dereference a constant cp_expr object:
   const cp_expr thing = ...;
   tree bob = *thing; // ERROR

What happens is the non-const operator * is not suitable, but the 
implicit conversion to a tree is, which is then dereferenced.  so we end 
up trying to assign a struct to a pointer-to-struct.

cp_expr::operator-> has a similar problem.

The attached patch adds const-qualified accessors.

I also noticed that some of the values of cp_tree_node_structure_enum 
were no longer used, leading to warnings about them not being handled in 
switch statements.  (We never use LAST_TS_CP_ENUM to size an array).

Deleted in this patch.

Applying to trunk.

nathan
diff mbox series

Patch

2017-10-12  Nathan Sidwell  <nathan@acm.org>

	* cp-tree.h (cp_expr): Add const operator * and operator->
	accessors.
	(cp_tree_node_structure_enum): Delete TS_CP_BINDING,
	TS_CP_WRAPPER, LAST_TS_CP_ENUM.

Index: cp-tree.h
===================================================================
--- cp-tree.h	(revision 253683)
+++ cp-tree.h	(working copy)
@@ -65,7 +65,9 @@  public:
   /* Implicit conversions to tree.  */
   operator tree () const { return m_value; }
   tree & operator* () { return m_value; }
+  tree operator* () const { return m_value; }
   tree & operator-> () { return m_value; }
+  tree operator-> () const { return m_value; }
 
   tree get_value () const { return m_value; }
   location_t get_location () const { return m_loc; }
@@ -1467,11 +1469,9 @@  enum cp_tree_node_structure_enum {
   TS_CP_IDENTIFIER,
   TS_CP_TPI,
   TS_CP_PTRMEM,
-  TS_CP_BINDING,
   TS_CP_OVERLOAD,
   TS_CP_BASELINK,
   TS_CP_TEMPLATE_DECL,
-  TS_CP_WRAPPER,
   TS_CP_DEFAULT_ARG,
   TS_CP_DEFERRED_NOEXCEPT,
   TS_CP_STATIC_ASSERT,
@@ -1480,8 +1480,7 @@  enum cp_tree_node_structure_enum {
   TS_CP_LAMBDA_EXPR,
   TS_CP_TEMPLATE_INFO,
   TS_CP_CONSTRAINT_INFO,
-  TS_CP_USERDEF_LITERAL,
-  LAST_TS_CP_ENUM
+  TS_CP_USERDEF_LITERAL
 };
 
 /* The resulting tree type.  */