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

[Clang] Requires expression incorrectly use non-static methods from generic lambda inside static method #110785

Closed
ksh4699 opened this issue Oct 2, 2024 · 1 comment · Fixed by #111277
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" concepts C++20 concepts confirmed Verified by a second party diverges-from:edg Does the clang frontend diverge from edg compiler diverges-from:gcc Does the clang frontend diverge from gcc on this issue diverges-from:msvc Does the clang frontend diverge from msvc on this issue regression:19 Regression in 19 release

Comments

@ksh4699
Copy link

ksh4699 commented Oct 2, 2024

Compiler Explorer: https://godbolt.org/z/66397fTff

struct Foo {
    static void f(auto) requires(false) {}
    void f(int) {}

    static void g() {
        static constexpr auto b = [](auto v) {
            return requires { f(v); };
        } (0);
        static_assert(b == false);
    }
};

Clang versions <= 18 and other compilers accept this program. The requires expression should be false, since f(0) is ill-formed in the context inside the lambda.

@github-actions github-actions bot added the clang Clang issues not falling into any other category label Oct 2, 2024
@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" concepts C++20 concepts and removed clang Clang issues not falling into any other category labels Oct 2, 2024
@llvmbot
Copy link
Member

llvmbot commented Oct 2, 2024

@llvm/issue-subscribers-clang-frontend

Author: None (ksh4699)

Compiler Explorer: https://godbolt.org/z/66397fTff
struct Foo {
    static void f(auto) requires(false) {}
    void f(int) {}

    static void g() {
        static constexpr auto b = [](auto v) {
            return requires { f(v); };
        } (0);
        static_assert(b == false);
    }
};

Clang versions <= 18 and other compilers accept this program. The requires expression should be false, since f(0) is ill-formed in the context inside the lambda.

@zyn0217 zyn0217 added confirmed Verified by a second party diverges-from:gcc Does the clang frontend diverge from gcc on this issue diverges-from:msvc Does the clang frontend diverge from msvc on this issue diverges-from:edg Does the clang frontend diverge from edg compiler regression:19 Regression in 19 release labels Oct 2, 2024
@zyn0217 zyn0217 closed this as completed in 8c15470 Oct 7, 2024
llvmbot pushed a commit to llvmbot/llvm-project that referenced this issue Oct 7, 2024
…solvedCallExpr() after fd87d76 (llvm#111277)

The special-casing for RequiresExprBodyDecl caused a regression, as
reported in llvm#110785.

The original fix for llvm#84020 has been superseded by fd87d76, which
establishes a `DependentScopeDeclRefExpr` instead of a
`CXXDependentScopeMemberExpr` for the case in issue. So the spurious
diagnostic in llvm#84020 would no longer occur.

This also merges the test for llvm#84020 together with that for llvm#110785 into
clang/test/SemaTemplate/instantiate-requires-expr.cpp.

No release note because I think this merits a backport.

Fixes llvm#110785

(cherry picked from commit 8c15470)
tru pushed a commit to llvmbot/llvm-project that referenced this issue Oct 11, 2024
…solvedCallExpr() after fd87d76 (llvm#111277)

The special-casing for RequiresExprBodyDecl caused a regression, as
reported in llvm#110785.

The original fix for llvm#84020 has been superseded by fd87d76, which
establishes a `DependentScopeDeclRefExpr` instead of a
`CXXDependentScopeMemberExpr` for the case in issue. So the spurious
diagnostic in llvm#84020 would no longer occur.

This also merges the test for llvm#84020 together with that for llvm#110785 into
clang/test/SemaTemplate/instantiate-requires-expr.cpp.

No release note because I think this merits a backport.

Fixes llvm#110785

(cherry picked from commit 8c15470)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" concepts C++20 concepts confirmed Verified by a second party diverges-from:edg Does the clang frontend diverge from edg compiler diverges-from:gcc Does the clang frontend diverge from gcc on this issue diverges-from:msvc Does the clang frontend diverge from msvc on this issue regression:19 Regression in 19 release
Projects
None yet
4 participants