This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [C++ PATCH] Issue hard error even with -fpermissive for certain goto violations (PR c++/67409)


On 18/11/15 22:55, Jakub Jelinek wrote:

  static bool
-identify_goto (tree decl, const location_t *locus)
+identify_goto (tree decl, const location_t *locus, bool harderr)
  {
-  bool complained = (decl
-		     ? permerror (input_location, "jump to label %qD", decl)
-		     : permerror (input_location, "jump to case label"));
+  bool complained;
+  if (!harderr)
+    {
+      if (decl)
+	complained = permerror (input_location, "jump to label %qD", decl);
+      else
+	complained = permerror (input_location, "jump to case label");
+    }
+  else
+    {
+      if (decl)
+	error ("jump to label %qD", decl);
+      else
+	error ("jump to case label");
+      complained = true;
+    }
    if (complained && locus)
      inform (*locus, "  from here");
    return complained;

The above is a bit repetitive. Why not simply?

static bool
error_jumpto (diagnostic_t kind, location_t loc, tree decl)
{
  bool complained = (decl
		     ? emit_diagnostic (kind, input_location, 0,
					"jump to label %qD", decl)
		     : emit_diagnostic (kind, input_location, 0,
					"jump to case label"));
  if (complained && loc)
    inform (loc, " from here");
  return complained;
}

That is, call a function that gives errors about X, error_X; no point in passing a pointer to location_t; most diagnostic functions take loc as the first argument; no obscure bool parameter. Then call:

@@ -2991,15 +3004,16 @@ check_previous_goto_1 (tree decl, cp_bin
  		       bool exited_omp, const location_t *locus)
  {
    cp_binding_level *b;
-  bool identified = false, complained = false;
+  bool complained = false;
+  int identified = 0;
    bool saw_eh = false, saw_omp = false, saw_tm = false;

    if (exited_omp)
      {
-      complained = identify_goto (decl, locus);
+      complained = identify_goto (decl, locus, true);

complained = error_jumpto (DK_ERROR, loc, decl);

+	      complained = identify_goto (decl, locus, false);

complained = error_jumpto (DK_PERMERROR, loc, decl);


+      if (ent->in_try_scope || ent->in_catch_scope
+	  || ent->in_transaction_scope || ent->in_omp_scope)
+	{
+	  error_at (DECL_SOURCE_LOCATION (decl), "jump to label %qD", decl);
+	  complained = true;
+	  identified = 2;
+	}
+      else
+	{
+	  complained = permerror (DECL_SOURCE_LOCATION (decl),
+				  "jump to label %qD", decl);
+	  identified = 1;
+	}
       if (complained)
 	inform (input_location, "  from here");

Note that if the function above takes another location_t argument, you can also simplify this hunk to:

      diagnostic_t kind;
      if (ent->in_try_scope || ent->in_catch_scope
	  || ent->in_transaction_scope || ent->in_omp_scope)
	{
          kind = DK_ERROR;
	  identified = 2;
	}
       else
	{
	  kind = DK_PERMERROR;
	  identified = 1;
	}
	complained = error_jumpto (kind, loc, DECL_SOURCE_LOCATION (decl), decl);

You can even use kind (maybe 'error_kind') directly instead of identified for what you are trying to achieve, with error_kind in {DK_UNSPECIFIED, DK_ERROR, DK_PERMERROR}.



    FOR_EACH_VEC_SAFE_ELT (ent->bad_decls, ix, bad)
@@ -3155,6 +3180,14 @@ check_goto (tree decl)
        if (u > 1 && DECL_ARTIFICIAL (bad))
  	{
  	  /* Can't skip init of __exception_info.  */
+	  if (identified == 1)
+	    {
+	      error_at (DECL_SOURCE_LOCATION (decl),
+			"jump to label %qD", decl);
+	      inform (input_location, "  from here");
+	      complained = true;
+	      identified = 2;
+	    }

and here:

 kind = DK_ERROR;
 complained = error_jumpto (kind, input_location,
                            DECL_SOURCE_LOCATION (decl), decl);

  	  if (complained)
  	    inform (DECL_SOURCE_LOCATION (bad), "  enters catch block");
  	  saw_catch = true;
@@ -3195,13 +3228,13 @@ check_goto (tree decl)
  	    break;
  	  if (b->kind == sk_omp)
  	    {
-	      if (!identified)
+	      if (identified < 2)
  		{
-		  complained = permerror (DECL_SOURCE_LOCATION (decl),
-					  "jump to label %qD", decl);
-		  if (complained)
-		    inform (input_location, "  from here");
-		  identified = true;
+		  error_at (DECL_SOURCE_LOCATION (decl),
+			    "jump to label %qD", decl);
+		  inform (input_location, "  from here");
+		  complained = true;
+		  identified = 2;
  		}

and the same here.

Cheers,

Manuel.




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]