llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
26.71k stars 10.94k forks source link

Support Wchanges-meaning? #77970

Open shafik opened 5 months ago

shafik commented 5 months ago

Currently given the following C++ code:

enum {i=1};

class A {
  char arr[i]; 
  enum {i=2}; // IFNDR changes meaning of i
}; 

struct B {};
struct C {
    typedef B B_type;

    void B(); // IFNDR changes meaning of B
};

gcc diagnoses this code under -Wchanges-meaning: https://godbolt.org/z/rY4W5h31n

This IFNDR according to class.member.lookup p6

gcc used to diagnose this under -fpermissive.

Maybe we should also consider supporting this diagnostic.

Endilll commented 5 months ago

N1543 "Analysis and Proposed Resolution for Core Issue 39" should help understanding the intent behind wording in class.member.lookup p6.

erichkeane commented 5 months ago

Note that a WG21 paper on this topic (P1697) was accepted by the evolution group in mid 2019(https://github.com/cplusplus/papers/issues/469), and was held up on implementation experience in CWG.

I suspect if an author can properly diagnose this as GCC does, they could/should also pick up P1697 and see if we can make this a hard-error via-standard rather than a warning.