public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/111269] New: Confusing location of error in source code
@ 2023-09-01 13:24 alx at kernel dot org
  2023-09-01 16:55 ` [Bug c/111269] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: alx at kernel dot org @ 2023-09-01 13:24 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111269

            Bug ID: 111269
           Summary: Confusing location of error in source code
           Product: gcc
           Version: 13.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: alx at kernel dot org
  Target Milestone: ---

I've been confused for some time with a compilation error that
pointed to a slightly-off location.  I wasn't seeing that I used
a temporary variable in a constant expression.  The code could be
reduced to:

$ cat const.c 
int
main(void)
{
        int x = 42;

        _Static_assert(0 || 7 > x, "");
}
$ gcc-13 -Wall -Wextra const.c
const.c: In function ‘main’:
const.c:6:26: error: expression in static assertion is not constant
    6 |         _Static_assert(0 || 7 > x, "");
      |                        ~~^~~~~~~~
$ clang-16 -Weverything const.c
const.c:6:26: error: static assertion expression is not an integral constant
expression
        _Static_assert(0 || 7 > x, "");
                       ~~~~~~~~~^
1 error generated.


Clang points to the precise location of the problem, while GCC is too fuzzy.

I suspect this is a duplicate of other bugs, but I'm not sure, so I'll let you
decide that.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c/111269] Confusing location of error in source code
  2023-09-01 13:24 [Bug c/111269] New: Confusing location of error in source code alx at kernel dot org
@ 2023-09-01 16:55 ` pinskia at gcc dot gnu.org
  2023-09-01 16:55 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-01 16:55 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111269

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
           Keywords|                            |diagnostic
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2023-09-01

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
It is pointing to the whole expression and just the outermost operator, || .

Now the C++ front-end gives a better location and information on why it is not
a constant expression:
<source>: In function 'int main()':
<source>:11:26: error: non-constant condition for static assertion
   11 |         _Static_assert(0 || 7 > x, "");
      |                        ~~^~~~~~~~
<source>:11:33: error: the value of 'x' is not usable in a constant expression
   11 |         _Static_assert(0 || 7 > x, "");
      |                                 ^
<source>:9:13: note: 'int x' is not const
    9 |         int x = 42;
      |             ^


The C front-end could do better ...

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c/111269] Confusing location of error in source code
  2023-09-01 13:24 [Bug c/111269] New: Confusing location of error in source code alx at kernel dot org
  2023-09-01 16:55 ` [Bug c/111269] " pinskia at gcc dot gnu.org
@ 2023-09-01 16:55 ` pinskia at gcc dot gnu.org
  2023-09-02  0:29 ` [Bug c/111269] location for non-constant expressions inside static assert could be better alx at kernel dot org
  2023-09-02  0:29 ` alx at kernel dot org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-01 16:55 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111269

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c/111269] location for non-constant expressions inside static assert could be better
  2023-09-01 13:24 [Bug c/111269] New: Confusing location of error in source code alx at kernel dot org
  2023-09-01 16:55 ` [Bug c/111269] " pinskia at gcc dot gnu.org
  2023-09-01 16:55 ` pinskia at gcc dot gnu.org
@ 2023-09-02  0:29 ` alx at kernel dot org
  2023-09-02  0:29 ` alx at kernel dot org
  3 siblings, 0 replies; 5+ messages in thread
From: alx at kernel dot org @ 2023-09-02  0:29 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111269

--- Comment #2 from Alejandro Colomar <alx at kernel dot org> ---
Hi Andrew,

On 2023-09-01 18:55, pinskia at gcc dot gnu.org wrote:
> It is pointing to the whole expression and just the outermost operator, || .

That's what I suspected.

>
> Now the C++ front-end gives a better location and information on why it is not
> a constant expression:
> <source>: In function 'int main()':
> <source>:11:26: error: non-constant condition for static assertion
>    11 |         _Static_assert(0 || 7 > x, "");
>       |                        ~~^~~~~~~~
> <source>:11:33: error: the value of 'x' is not usable in a constant expression
>    11 |         _Static_assert(0 || 7 > x, "");
>       |                                 ^
> <source>:9:13: note: 'int x' is not const
>     9 |         int x = 42;
>       |             ^
>
>
> The C front-end could do better ...

Yep, g++ seems good here.  If it's something easy that I could do, I'd
love some pointer to the code I should look at to do the same that the
C++ front end does.

Cheers,
Alex

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c/111269] location for non-constant expressions inside static assert could be better
  2023-09-01 13:24 [Bug c/111269] New: Confusing location of error in source code alx at kernel dot org
                   ` (2 preceding siblings ...)
  2023-09-02  0:29 ` [Bug c/111269] location for non-constant expressions inside static assert could be better alx at kernel dot org
@ 2023-09-02  0:29 ` alx at kernel dot org
  3 siblings, 0 replies; 5+ messages in thread
From: alx at kernel dot org @ 2023-09-02  0:29 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111269

--- Comment #3 from Alejandro Colomar <alx at kernel dot org> ---
On 2023-09-01 18:57, pinskia at gcc dot gnu.org wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111269
>
> Andrew Pinski <pinskia at gcc dot gnu.org> changed:
>
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>            See Also|                            |https://gcc.gnu.org/bugzill
>                    |                            |a/show_bug.cgi?id=55678
>

Did you accidentally point to a different bug?
I don't think that one is related at all.

        _Static_assert escapes tick marks just to make me mad

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-09-02  0:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-01 13:24 [Bug c/111269] New: Confusing location of error in source code alx at kernel dot org
2023-09-01 16:55 ` [Bug c/111269] " pinskia at gcc dot gnu.org
2023-09-01 16:55 ` pinskia at gcc dot gnu.org
2023-09-02  0:29 ` [Bug c/111269] location for non-constant expressions inside static assert could be better alx at kernel dot org
2023-09-02  0:29 ` alx at kernel dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).