Skip to content

Inconsitency between variable decltype(auto) in variables and templates #47136

Closed
@yeah-boi

Description

@yeah-boi
mannequin
Bugzilla Link 47792
Version trunk
OS All
CC @hubert-reinterpretcast,@zygoloid

Extended Description

Consider the following program:

#include
#include <type_traits>

template<decltype(auto) N>
void f()
{
std::cout << std::is_same_v<decltype(N), int> << std::endl;
}

int main()
{
const int i = 0;

f<i>();

decltype(auto) N = i;
std::cout << std::is_same_v<decltype(N), const int> << std::endl;

}

When compiling it with -std=c++17 -pedantic-errors and the running it the following is outputed:

1
1

This means that the two decltype(auto) deductions behaved differently since they deduced different types ( N = int and N = const int ). I expect them to behave the same way.

Note that gcc gives the expected result ( N = const int for both deductions ).

Link to compiler explorer (clang to the left, gcc to the right):

https://godbolt.org/z/Y5Yc7M

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillac++17clang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second party

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions