Skip to content

Compiler confused when compiling template variable initialized by lambda-expression with default parameter. #33352

@llvmbot

Description

@llvmbot
Bugzilla Link 34005
Version trunk
OS All
Reporter LLVM Bugzilla Contributor
CC @Quuxplusone

Extended Description

The code below fail to be compile.

// prog.cc

template<int> struct X {};
template<int n> constexpr void f(X<n>) {}
template<typename> constexpr int v = [](int r = 0l) constexpr { return r; }();

int main() {
    f<v<int>>(X<0>());
}
$ clang++ -std=c++1z prog.cc

prog.cc:6:5: error: no matching function for call to 'f'
    f<v<int>>(X<0>());
    ^~~~~~~~~
prog.cc:2:32: note: candidate function not viable: no known conversion from 'X<...>' to 'X<...>' for 1st argument
template<int n> constexpr void f(X<n>) {}
                               ^
1 error generated.

I think v<T> is always 0, so f<v<int>>(X<0>()) should match f<0>(X<0>);

And if lambda's default parameter type is int,

template<typename> constexpr int v = [](int r = 0) constexpr { return r; }();

There are no errors.

This link is the result executed by wandbox.
https://wandbox.org/permlink/yjKqrYKQyl2YZ6PO

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillaclang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second partyconstexprAnything related to constant evaluationcrash-on-validlambdaC++11 lambda expressions

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions