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 for c++/81676 - bogus -Wunused warnings in constexpr if


On 8/16/19 2:29 PM, Marek Polacek wrote:
This patch is an attempt to fix the annoying -Wunused-but-set-* warnings that
tend to occur with constexpr if.  When we have something like

   template < typename T >
   int f(T v){
       if constexpr(sizeof(T) == sizeof(int)){
	  return v;
       }else{
	  return 0;
       }
   }

and call f('a'), then the condition is false, meaning that we won't instantiate
the then-branch, as per tsubst_expr/IF_STMT:
17284       if (IF_STMT_CONSTEXPR_P (t) && integer_zerop (tmp))
17285         /* Don't instantiate the THEN_CLAUSE. */;
so we'll never get round to mark_exp_read-ing the decls used in the
then-branch, causing finish_function to emit "parameter set but not used"
warnings.

It's unclear how to best deal with this.  Marking the decls DECL_READ_P while
parsing doesn't seem like a viable approach

Why not?

Jason


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