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

            Bug ID: 119082
           Summary: GCC Incorrectly Accepts Explicit Destructor Call for
                    Scalar Type in constexpr Context
           Product: gcc
           Version: 13.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: qurong at ios dot ac.cn
  Target Milestone: ---

GCC 12.4/13.3/11.4 erroneously compiles code that explicitly calls the
destructor of a scalar type (e.g., int) within a constexpr function, while
MSVC/Clang correctly reject it. This violates the C++ standard rules.

For the following code test.cpp:

```
template <typename T>
constexpr bool test_scope() {
    {
        T x{};
        x.~T(); // Ill-formed if T is a scalar type (e.g., int)
    }
    return true;
}

int main() {
    constexpr bool a = test_scope<int>();
    return 0;
}
```

Compile with GCC:
g++ -std=c++20 test.cpp
Expected Result:
Compilation fails with an error about invalid destructor call for scalar types.

Actual Result:
GCC compiles the code without errors.

Environment:
Compiler: GCC 12.4/13.3/11.4
Flags: -std=c++20

Standard References:
C++20 §7.6.1.4: "The use of a pseudo-destructor-name after a dot . or arrow ->
operator represents the destructor for the non-class type denoted by the
type-name [...] The result can only be used as the operand for the function
call operator ()."
C++20 §7.6.1.4/5: "The postfix-expression before the dot . or arrow -> shall
have class type."


Compiler Explorer link: https://godbolt.org/z/5W1b4zWoj

Reply via email to