public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Confusing location of error in source code
@ 2023-08-31 16:04 Alejandro Colomar
  2023-09-01  6:49 ` Jonathan Wakely
  0 siblings, 1 reply; 3+ messages in thread
From: Alejandro Colomar @ 2023-08-31 16:04 UTC (permalink / raw)
  To: GCC


[-- Attachment #1.1: Type: text/plain, Size: 827 bytes --]

Hi!

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, "");
}
$ cc -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, "");
      |                        ~~^~~~~~~~


I think the appropriate error report should point to this other point:


    6 |         _Static_assert(0 || 7 > x, "");
      |                        ~~~~~~~~~^

Cheers,
Alex

-- 
<http://www.alejandro-colomar.es/>
GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: Confusing location of error in source code
  2023-08-31 16:04 Confusing location of error in source code Alejandro Colomar
@ 2023-09-01  6:49 ` Jonathan Wakely
  2023-09-01 13:17   ` Alejandro Colomar
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Wakely @ 2023-09-01  6:49 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: GCC

[-- Attachment #1: Type: text/plain, Size: 889 bytes --]

On Thu, 31 Aug 2023, 17:05 Alejandro Colomar via Gcc, <gcc@gcc.gnu.org>
wrote:

> Hi!
>
> 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, "");
> }
> $ cc -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, "");
>       |                        ~~^~~~~~~~
>
>
> I think the appropriate error report should point to this other point:
>
>
>     6 |         _Static_assert(0 || 7 > x, "");
>       |                        ~~~~~~~~~^
>

Please use bugzilla for bug reports.

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

* Re: Confusing location of error in source code
  2023-09-01  6:49 ` Jonathan Wakely
@ 2023-09-01 13:17   ` Alejandro Colomar
  0 siblings, 0 replies; 3+ messages in thread
From: Alejandro Colomar @ 2023-09-01 13:17 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: GCC


[-- Attachment #1.1: Type: text/plain, Size: 1137 bytes --]

Hi Jonathan,

On 2023-09-01 08:49, Jonathan Wakely wrote:
> On Thu, 31 Aug 2023, 17:05 Alejandro Colomar via Gcc, <gcc@gcc.gnu.org>
> wrote:
> 
>> Hi!
>>
>> 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, "");
>> }
>> $ cc -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, "");
>>       |                        ~~^~~~~~~~
>>
>>
>> I think the appropriate error report should point to this other point:
>>
>>
>>     6 |         _Static_assert(0 || 7 > x, "");
>>       |                        ~~~~~~~~~^
>>
> 
> Please use bugzilla for bug reports.

Sure, will do.  Thanks!

Alex

> 

-- 
<http://www.alejandro-colomar.es/>
GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

end of thread, other threads:[~2023-09-01 13:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-31 16:04 Confusing location of error in source code Alejandro Colomar
2023-09-01  6:49 ` Jonathan Wakely
2023-09-01 13:17   ` Alejandro Colomar

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).