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 rejects call to base class member function inside requires inside constexpr if using scope resolution operator #83979

Closed
ranaanoop opened this issue Mar 5, 2024 · 3 comments
Labels
c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema" concepts C++20 concepts duplicate Resolved as duplicate

Comments

@ranaanoop
Copy link

The following program is rejected by clang :Demo

#include<type_traits>
  
template<typename T>
struct AlwaysFalse : public std::false_type {};

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

template <typename T,typename S>
struct A:T
{
  auto foo(){
    if constexpr (requires{T::template foo<S>();})
    return 1;
    else
       static_assert(AlwaysFalse<A>::value,
                    "foo is not implemented.");
  }
};

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

Clang says:

<source>:19:22: error: static assertion failed due to requirement 'AlwaysFalse<A<B, double>>::value': foo is not implemented.
   19 |        static_assert(AlwaysFalse<A>::value,
      |                      ^~~~~~~~~~~~~~~~~~~~~
<source>:27:3: note: in instantiation of member function 'A<B, double>::foo' requested here
   27 | a.foo();
      |   ^
1 error generated.
Compiler returned: 1

Note program work if we change constexpr if to if constexpr (requires(T t){t. template foo<S>();}). Demo

@github-actions github-actions bot added the clang Clang issues not falling into any other category label Mar 5, 2024
@ranaanoop ranaanoop changed the title Clang rejects call to base class member function inside requires inside constexpr if using scope resolution operatot Clang rejects call to base class member function inside requires inside constexpr if using scope resolution operator Mar 5, 2024
@EugeneZelenko EugeneZelenko added c++20 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 Mar 5, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Mar 5, 2024

@llvm/issue-subscribers-clang-frontend

Author: Anoop Rana (ranaanoop)

The following program is rejected by clang :[Demo](https://godbolt.org/z/34ra7aM1s) ``` #include<type_traits>

template<typename T>
struct AlwaysFalse : public std::false_type {};

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

template <typename T,typename S>
struct A:T
{
auto foo(){
if constexpr (requires{T::template foo<S>();})
return 1;
else
static_assert(AlwaysFalse<A>::value,
"foo is not implemented.");
}
};

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


Clang says:

<source>:19:22: error: static assertion failed due to requirement 'AlwaysFalse<A<B, double>>::value': foo is not implemented.
19 | static_assert(AlwaysFalse<A>::value,
| ^~~~~~~~~~~~~~~~~~~~~
<source>:27:3: note: in instantiation of member function 'A<B, double>::foo' requested here
27 | a.foo();
| ^
1 error generated.
Compiler returned: 1


---

Note program work if we change constexpr if to `if constexpr (requires(T t){t. template foo&lt;S&gt;();})`. [Demo](https://godbolt.org/z/jKGfenq1o)
</details>

@llvmbot
Copy link
Collaborator

llvmbot commented Mar 5, 2024

@llvm/issue-subscribers-c-20

Author: Anoop Rana (ranaanoop)

The following program is rejected by clang :[Demo](https://godbolt.org/z/34ra7aM1s) ``` #include<type_traits>

template<typename T>
struct AlwaysFalse : public std::false_type {};

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

template <typename T,typename S>
struct A:T
{
auto foo(){
if constexpr (requires{T::template foo<S>();})
return 1;
else
static_assert(AlwaysFalse<A>::value,
"foo is not implemented.");
}
};

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


Clang says:

<source>:19:22: error: static assertion failed due to requirement 'AlwaysFalse<A<B, double>>::value': foo is not implemented.
19 | static_assert(AlwaysFalse<A>::value,
| ^~~~~~~~~~~~~~~~~~~~~
<source>:27:3: note: in instantiation of member function 'A<B, double>::foo' requested here
27 | a.foo();
| ^
1 error generated.
Compiler returned: 1


---

Note program work if we change constexpr if to `if constexpr (requires(T t){t. template foo&lt;S&gt;();})`. [Demo](https://godbolt.org/z/jKGfenq1o)
</details>

@shafik
Copy link
Collaborator

shafik commented Mar 7, 2024

Duplicate: #84020

When a bug comes from a Stackoverflow we should link to the SO post for reference, this should also help to catch duplicates when screening bugs, thank you!

@shafik shafik closed this as not planned Won't fix, can't repro, duplicate, stale Mar 7, 2024
@EugeneZelenko EugeneZelenko added the duplicate Resolved as duplicate label Mar 7, 2024
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 duplicate Resolved as duplicate
Projects
None yet
Development

No branches or pull requests

4 participants