This is the mail archive of the gcc@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]

Invalid code in <limits>


The C++ standard library <limits> code contains this pattern:

      static const bool has_infinity
	= __builtin_huge_valf () / 2 == __builtin_huge_valf ();

in several places.

Syntactically, a function call cannot appear in a constant-expression,
which is what is required for a static member initializer.  

I've got patches to correctly diagnose this error, and they're
tripping on this code in the standard library.

Theoretically, we could try to exempt built-ins, but it is going to
get very complicated to try to get that right in the presence of
templates/dependent names/two-phase name lookup.  We really don't want
to go there.

One way to fix this would to be to introduce magic variables as well
as the builtin functions.  These magic variables would be defined
like:

  static const __builtin_huge_valf_constant = <the value>;

Or maybe have the preprocessor define symbols ala __SIZE_TYPE__ for
this purpose?

Or maybe magic keywords?

Thoughts?

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com


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