C++ Logo

std-discussion

Advanced search

Re: Question about name lookup and class member?

From: Andrew Schepler <aschepler_at_[hidden]>
Date: Mon, 7 Jun 2021 12:39:59 -0400
On Mon, Jun 7, 2021 at 4:31 AM Eric Suen via Std-Discussion <
std-discussion_at_[hidden]> wrote:

> Does this apply to default template arguments? this cause some weird
> bugs of compilers
>
> #include <iostream>
>
> struct A {
> template<int V = 1 + /*F<1>()*/> //no syntax error in MSVC
> int test() {
> return V;
> }
>
> template<int V>
> static constexpr int F() {
> return V;
> }
> };
>
> int main() {
> std::cout << A().test<1>();
> std::cout << A().test<>(); //error in MSVC
> }
>

(I assume you didn't mean to comment out the "F<1>()" expression, since
"template<int V = 1 + >" is certainly a syntax error.)

No, a default template argument is not a complete-class context (
[class.mem]/6 <https://timsong-cpp.github.io/cppwp/n4861/class.mem#6>).
Clang++ and g++ are correct to complain that "F" is not declared.

-- Andrew Schepler

Received on 2021-06-07 11:40:17