[Bug c/80756] missing diagnostic on non-constant expression with function call such as fabs or fma in initializer

2021-09-29 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80756

Andrew Pinski  changed:

   What|Removed |Added

 Resolution|--- |INVALID
 Status|UNCONFIRMED |RESOLVED

--- Comment #7 from Andrew Pinski  ---
As mentioned -std=c99 -pedantic-errors errors out like expected.

[Bug c/80756] missing diagnostic on non-constant expression with function call such as fabs or fma in initializer

2017-05-15 Thread joseph at codesourcery dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80756

--- Comment #6 from joseph at codesourcery dot com  ---
On Mon, 15 May 2017, nsz at gcc dot gnu.org wrote:

> fabs and fma identifiers are reserved for the implementation and it is valid 
> to
> treat them as constant expression in initializers based on c99 6.6p10

The calls violate the requirement for constant expressions not to contain 
function calls, hence the pedwarns-if-pedantic being necessary for this 
code.

[Bug c/80756] missing diagnostic on non-constant expression with function call such as fabs or fma in initializer

2017-05-15 Thread joseph at codesourcery dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80756

--- Comment #5 from joseph at codesourcery dot com  ---
On Mon, 15 May 2017, vincent-gcc at vinc17 dot net wrote:

> GCC misses a diagnostic when the fabs() or fma() function is used in an
> initializer. For instance, consider:

There are pedwarns-if-pedantic for these cases.

> Note that  is not included, so that fabs() and fma() must not be
> regarded as special. But even when these functions are regarded as ISO C's
> specified ones, the diagnostic should probably still be present (it seems that
> the C standard does not make an exception for such functions, unfortunately).

The reservations with external linkage in C99/C11 7.1.3#1 are not 
conditional on whether the corresponding header is included.  (Only C90 
Amendment 1 had such reservations conditional on inclusion of the 
corresponding header, for the new functions it added, and that condition 
would only be relevant with -std=iso9899:199409.)

[Bug c/80756] missing diagnostic on non-constant expression with function call such as fabs or fma in initializer

2017-05-15 Thread vincent-gcc at vinc17 dot net
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80756

--- Comment #4 from Vincent Lefèvre  ---
(In reply to nsz from comment #3)
> fabs and fma identifiers are reserved for the implementation and it is valid
> to treat them as constant expression in initializers based on c99 6.6p10

Well, if  is included, perhaps, but this would need to be documented as
an implementation-defined behavior. The GCC manual Section 4 "C
Implementation-Defined Behavior" doesn't seem to document such constant
expressions and when they are available.

If  is not included, there should be at least a warning because fabs()
or fma() is used without including the header first, thus potentially yielding
unexpected results and obscure bugs.

[Bug c/80756] missing diagnostic on non-constant expression with function call such as fabs or fma in initializer

2017-05-15 Thread nsz at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80756

nsz at gcc dot gnu.org changed:

   What|Removed |Added

 CC||nsz at gcc dot gnu.org

--- Comment #3 from nsz at gcc dot gnu.org ---
fabs and fma identifiers are reserved for the implementation and it is valid to
treat them as constant expression in initializers based on c99 6.6p10

i think the gcc behaviour is reasonable.

[Bug c/80756] missing diagnostic on non-constant expression with function call such as fabs or fma in initializer

2017-05-15 Thread vincent-gcc at vinc17 dot net
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80756

--- Comment #2 from Vincent Lefèvre  ---
(In reply to Vincent Lefèvre from comment #1)
> The cause seems to be that the functions are builtins:
> 
> $ gcc-snapshot -std=c99 -c tst-cst.c
[...]

Oops, incomplete copy-paste. It should have been:

$ gcc-snapshot -std=c99 -c tst-cst.c -fno-builtin
tst-cst.c: In function 'f':
tst-cst.c:7:21: error: initializer element is not constant
   static double x = fabs (3.0);
 ^~~~
tst-cst.c:8:21: error: initializer element is not constant
   static double y = fma (2.0, 3.0, 4.0);
 ^~~
tst-cst.c:9:21: error: initializer element is not constant
   static double z = foo (2.0, 3.0, 4.0);
 ^~~

Without the -fno-builtin, the diagnostic for fabs() and fma() are missing.

[Bug c/80756] missing diagnostic on non-constant expression with function call such as fabs or fma in initializer

2017-05-15 Thread vincent-gcc at vinc17 dot net
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80756

--- Comment #1 from Vincent Lefèvre  ---
The cause seems to be that the functions are builtins:

$ gcc-snapshot -std=c99 -c tst-cst.c
tst-cst.c: In function 'f':
tst-cst.c:7:21: error: initializer element is not constant
   static double x = fabs (3.0);
 ^~~~
tst-cst.c:8:21: error: initializer element is not constant
   static double y = fma (2.0, 3.0, 4.0);
 ^~~
tst-cst.c:9:21: error: initializer element is not constant
   static double z = foo (2.0, 3.0, 4.0);
 ^~~

But I think that this is wrong. The use of -std=c99 shouldn't allow builtin
functions when they would give a different result (and even without -std=c99,
as this would be confusing). On this point, Clang has the same issue.