Skip to content

[Clang] Clang fails to deduce the type of variable member templates #134526

Closed
@zyn0217

Description

@zyn0217

The following code has been rejected since Clang 9, with a suspicious error:

template <class T>
struct S {
  template <class U>
  static const auto var = T();

  template <class U>
  static const auto foo = var<T>;
};

const int p = S<int>::var<int> + S<int>::foo<int>;
invalid operands to binary expression ('const auto' and 'const auto')
   10 | const int p = S<int>::var<int> + S<int>::foo<int>;
      |               ~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~

https://compiler-explorer.com/z/jc1To6c38

The code is accepted by GCC (since 5.1), MSVC but also rejected by EDG.

It's unclear to me if this is conforming per the standard, but from my gut feeling this should be valid

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"diverges-from:gccDoes the clang frontend diverge from gcc on this issuediverges-from:msvcDoes the clang frontend diverge from msvc on this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions