public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/114218] New: -Wdr could show constant values
@ 2024-03-03  7:38 sjames at gcc dot gnu.org
  2024-03-03  7:39 ` [Bug c++/114218] " sjames at gcc dot gnu.org
  2024-03-03  7:42 ` [Bug lto/114218] If there is an ODR violation due to array sizes being different, it would be useful to show what the sizes were pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: sjames at gcc dot gnu.org @ 2024-03-03  7:38 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114218
           Summary: -Wdr could show constant values
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sjames at gcc dot gnu.org
  Target Milestone: ---

It'd be a nice UX improvement if -Wodr showed the differing constant values
rather than just the identifier.

(This came up in the wild https://github.com/alsaplayer/alsaplayer/issues/28).

a.h:
```
#ifndef MAGIC_NUMBER
#define MAGIC_NUMBER 42
#endif

struct number_storage {
        int MY_NUMBERS[MAGIC_NUMBER];
};
```

b.cxx:
```
#include "a.h"

struct number_storage collection_1;
```

c.cxx
```
#define MAGIC_NUMBER 100
#include "a.h"

struct number_storage collection_2;

int main() {

}
```

```
$ g++ b.cxx c.cxx -Wall -Wextra -flto
a.h:5:8: warning: type ‘struct number_storage’ violates the C++ One Definition
Rule [-Wodr]
    5 | struct number_storage {
      |        ^
a.h:5:8: note: a different type is defined in another translation unit
    5 | struct number_storage {
      |        ^
a.h:6:13: note: the first difference of corresponding definitions is field
‘MY_NUMBERS’
    6 |         int MY_NUMBERS[MAGIC_NUMBER];
      |             ^
a.h:6:13: note: a field of same name but different type is defined in another
translation unit
    6 |         int MY_NUMBERS[MAGIC_NUMBER];
      |             ^
a.h:5:8: note: array types have different bounds
    5 | struct number_storage {
      |        ^
```

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

* [Bug c++/114218] -Wdr could show constant values
  2024-03-03  7:38 [Bug c++/114218] New: -Wdr could show constant values sjames at gcc dot gnu.org
@ 2024-03-03  7:39 ` sjames at gcc dot gnu.org
  2024-03-03  7:42 ` [Bug lto/114218] If there is an ODR violation due to array sizes being different, it would be useful to show what the sizes were pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: sjames at gcc dot gnu.org @ 2024-03-03  7:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Sam James <sjames at gcc dot gnu.org> ---
To be clear: what I'd like is if the warning included "MAGIC_NUMBER was 42 at
one instance, and 100 at another".

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

* [Bug lto/114218] If there is an ODR violation due to array sizes being different, it would be useful to show what the sizes were
  2024-03-03  7:38 [Bug c++/114218] New: -Wdr could show constant values sjames at gcc dot gnu.org
  2024-03-03  7:39 ` [Bug c++/114218] " sjames at gcc dot gnu.org
@ 2024-03-03  7:42 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-03  7:42 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
            Summary|-Wodr could show constant   |If there is an ODR
                   |values                      |violation due to array
                   |                            |sizes being different, it
                   |                            |would be useful to show
                   |                            |what the sizes were
           Severity|normal                      |enhancement
          Component|c++                         |lto
           Keywords|                            |diagnostic
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2024-03-03

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.

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

end of thread, other threads:[~2024-03-03  7:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-03  7:38 [Bug c++/114218] New: -Wdr could show constant values sjames at gcc dot gnu.org
2024-03-03  7:39 ` [Bug c++/114218] " sjames at gcc dot gnu.org
2024-03-03  7:42 ` [Bug lto/114218] If there is an ODR violation due to array sizes being different, it would be useful to show what the sizes were pinskia at gcc dot gnu.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).