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

            Bug ID: 122914
           Summary: GCC accepts invalid C++ code: `this.member` treated as
                    `this->member` (C++ beginner unsure if bug or GNU
                    extension)
           Product: gcc
           Version: 15.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: stuzyf at 163 dot com
  Target Milestone: ---

I am a beginner learning C++, so I am not sure whether this behavior is a GCC
bug or an intended GNU extension.

GCC accepts code that is not valid standard C++: accessing a member using
`this.member` instead of `this->member`.

According to the C++ standard, `this` is always a pointer of type `T*`, so
`this.member` is ill-formed and should be rejected. Clang correctly diagnoses
this as an error, but GCC silently accepts it, seemingly rewriting it as
`this->member`.

I could not find any documentation describing such an extension. Therefore,
I would like to confirm whether this is:
- an intentional GNU C++ extension, or
- a bug.

---------------------------------------
Environment
---------------------------------------
GCC version: x86-64 gcc 15.2
Clang version: x86-64 clang 21.1.0

---------------------------------------
Minimal reproducible example (https://godbolt.org/z/Y5q7TPMjW)
---------------------------------------

```cpp
template <bool V>
struct box {
    struct Config {
        static constexpr bool value = V;
    } config;

    void fun() {
        this.config.value;   // invalid in standard C++: `this` is a pointer
    }
};

Reply via email to