Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

decltype(&(C::member)) yields pointer-to-member type #40906

Closed
llvmbot opened this issue Apr 22, 2019 · 3 comments · Fixed by #89713
Closed

decltype(&(C::member)) yields pointer-to-member type #40906

llvmbot opened this issue Apr 22, 2019 · 3 comments · Fixed by #89713
Labels
accepts-invalid bugzilla Issues migrated from bugzilla c++ clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented Apr 22, 2019

Bugzilla Link 41561
Version trunk
OS All
Reporter LLVM Bugzilla Contributor
CC @hfinkel,@randomnetcat,@darkbuck,@riccibruno,@zygoloid

Extended Description

In some contexts, decltype(&(C::member)) yields a pointer to member type, but according to [expr.unary.op]/4, no pointer to member should be formed when the operand of the & operator is enclosed in parentheses.

http://eel.is/c++draft/expr.unary.op#4

The code below demonstrates this behavior. It compiles on all Clang versions I have tried between 3.2 and HEAD, even though I don't think it should.

#include <type_traits>
 
struct S {
    int x;

    static_assert(std::is_same<decltype(&(S::x)), int S::*>::value, ""); // !

    void foo() {
        static_assert(std::is_same<decltype(&(S::x)), int*>::value, ""); // OK
    }
};

static_assert(std::is_same<decltype(&(S::x)), int S::*>::value, ""); // !

int main() {
}
@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
@llvmbot llvmbot added the confirmed Verified by a second party label Jan 26, 2022
@AaronBallman AaronBallman added c++ clang:frontend Language frontend issues, e.g. anything involving "Sema" accepts-invalid and removed clang Clang issues not falling into any other category labels Jun 20, 2023
@AaronBallman
Copy link
Collaborator

Issue still reproduces as of Clang 16.0.0: https://gcc.godbolt.org/z/1r93K5KTa

@llvmbot
Copy link
Collaborator Author

llvmbot commented Jun 20, 2023

@llvm/issue-subscribers-clang-frontend

@llvmbot
Copy link
Collaborator Author

llvmbot commented Jun 20, 2023

@llvm/issue-subscribers-c-1

cor3ntin added a commit that referenced this issue May 3, 2024
…n unevaluated context should be invalid (#89713)

clang don't check whether the operand of the & operator is enclosed in
parantheses when pointer to member is formed in unevaluated context, for
example:

```cpp
struct foo { int val; };

int main() { decltype(&(foo::val)) ptr; }
```

`decltype(&(foo::val))` should be invalid, but clang accepts it. This PR
fixes this issue.

Fixes #40906.

---------

Co-authored-by: cor3ntin <corentinjabot@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepts-invalid bugzilla Issues migrated from bugzilla c++ clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party
Projects
None yet
2 participants