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

Compiler error for requires expression with templated base class member function #84020

Closed
rath3t opened this issue Mar 5, 2024 · 10 comments · Fixed by #85198
Closed

Compiler error for requires expression with templated base class member function #84020

rath3t opened this issue Mar 5, 2024 · 10 comments · Fixed by #85198
Labels
c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema" concepts C++20 concepts confirmed Verified by a second party

Comments

@rath3t
Copy link

rath3t commented Mar 5, 2024

The following code fails to compile with clang trunk and clang 16 (See godbolt link).
The templated member function is not found by clang and therefore the static_assert is triggered.

The struct A inherits from T and therefore the base class member function foo exists, thus the static_assert should not trigger.
It works for non-templated base class member functions though.

struct B {
    template <typename S>
    void foo();

    void bar();
};

template <typename T, typename S>
struct A : T {
    auto foo() {
        static_assert(requires { T::template foo<S>(); });  // fails with clang
        static_assert(requires { T::bar(); });  // works with clang and gcc 12.2
    }
};

int main() {
    A<B, double> a;
    a.foo();
}

Godbolt

@rath3t rath3t changed the title Compiler error for delayed template in Compiler error for requires expression with templated base class member function Mar 5, 2024
@EugeneZelenko EugeneZelenko added c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema" concepts C++20 concepts and removed new issue labels Mar 5, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Mar 5, 2024

@llvm/issue-subscribers-clang-frontend

Author: Alex_Mueller (rath3t)

The following code fails to compile with clang trunk and clang 16 (See godbolt link). The templated member function is not found by clang and therefore the `static_assert` is triggered.

The struct A inherits from T and therefore the base class member function foo exists, thus the static_assert should not trigger.
It works for non-templated base class member functions though.

struct B {
    template &lt;typename S&gt;
    void foo();

    void bar();
};

template &lt;typename T, typename S&gt;
struct A : T {
    auto foo() {
        static_assert(requires { T::template foo&lt;S&gt;(); });  // fails with clang
        static_assert(requires { T::bar(); });  // works with clang and gcc 12.2
    }
};

int main() {
    A&lt;B, double&gt; a;
    a.foo();
}

Godbolt

@llvmbot
Copy link
Collaborator

llvmbot commented Mar 5, 2024

@llvm/issue-subscribers-c-20

Author: Alex_Mueller (rath3t)

The following code fails to compile with clang trunk and clang 16 (See godbolt link). The templated member function is not found by clang and therefore the `static_assert` is triggered.

The struct A inherits from T and therefore the base class member function foo exists, thus the static_assert should not trigger.
It works for non-templated base class member functions though.

struct B {
    template &lt;typename S&gt;
    void foo();

    void bar();
};

template &lt;typename T, typename S&gt;
struct A : T {
    auto foo() {
        static_assert(requires { T::template foo&lt;S&gt;(); });  // fails with clang
        static_assert(requires { T::bar(); });  // works with clang and gcc 12.2
    }
};

int main() {
    A&lt;B, double&gt; a;
    a.foo();
}

Godbolt

@shafik
Copy link
Collaborator

shafik commented Mar 5, 2024

EDG reject both but MSVC accepts both: https://godbolt.org/z/7G8rPY9hz

I don't see why they should be rejected but not totally sure.

CC @erichkeane @cor3ntin

@erichkeane
Copy link
Collaborator

I don't have a good idea, but both lookups seem to me like they should work.

@Sirraide
Copy link
Contributor

Sirraide commented Mar 5, 2024

At a glance, this looks like it’s a duplicate of #83979?

@rath3t
Copy link
Author

rath3t commented Mar 5, 2024

@cor3ntin
Copy link
Contributor

cor3ntin commented Mar 5, 2024

@shafik I agree with Erich, both lookup should work.

@shafik
Copy link
Collaborator

shafik commented Mar 7, 2024

Ah yes somebody copied my stackoverflow post https://stackoverflow.com/questions/78106241/compiler-divergence-in-delayed-template-instantiation.

In the future it is helpful to link to Stackoverflow bugs, especially if someone on the committee already analyzed the bug then that makes screening a lot faster and we can get to more bugs.

@shafik shafik added the confirmed Verified by a second party label Mar 7, 2024
@rath3t
Copy link
Author

rath3t commented Mar 8, 2024

I will add the stack overflow link in the future thanks! Sorry for the confusion. For my defense though, the answer on stackoverflow came after I posted here.

@shafik
Copy link
Collaborator

shafik commented Mar 8, 2024

I will add the stack overflow link in the future thanks! Sorry for the confusion. For my defense though, the answer on stackoverflow came after I posted here.

It is also helpful for discoverability, if someone else has referenced that bug we can tie those bugs together quickly. Same reason to include assertions and backtraces in bug reports.

jcsxky added a commit that referenced this issue Apr 16, 2024
…ass member function (#85198)

Fix #84020
Skip checking implicit object parameter in the context of
`RequiresExprBodyDecl`.

Co-authored-by: huqizhi <[email protected]>
zyn0217 added a commit that referenced this issue Oct 7, 2024
…solvedCallExpr() after fd87d76 (#111277)

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

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

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

No release note because I think this merits a backport.

Fixes #110785
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
c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema" concepts C++20 concepts confirmed Verified by a second party
Projects
Status: Done
7 participants