Skip to content

Clang issue in CTAD #62925

Closed
Closed
@walge-laine

Description

@walge-laine

Clang fails to compile cppreference example code. See Compiler Explorer.

Activity

added
clang:frontendLanguage frontend issues, e.g. anything involving "Sema"
and removed on May 24, 2023
llvmbot

llvmbot commented on May 24, 2023

@llvmbot
Member

@llvm/issue-subscribers-c-20

llvmbot

llvmbot commented on May 24, 2023

@llvmbot
Member

@llvm/issue-subscribers-clang-frontend

shafik

shafik commented on May 24, 2023

@shafik
Collaborator

Code in question:

#include <map>

int main() {
   std::map m1 = {std::pair{"foo", 2}, {"bar", 3}}; // guide #2
   std::map m2(m1.begin(), m1.end()); // guide #1
}

Diagnostic:

<source>:4:13: error: no viable constructor or deduction guide for deduction of template arguments of 'map'
   std::map m1 = {std::pair{"foo", 2}, {"bar", 3}}; // guide #2
            ^
/opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/../../../../include/c++/12.2.0/bits/stl_map.h:204:7: note: candidate template ignored: couldn't infer template argument '_Key'
      map(const _Compare& __comp,
      ^
/opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/../../../../include/c++/12.2.0/bits/stl_map.h:283:2: note: candidate template ignored: couldn't infer template argument '_Key'
        map(_InputIterator __first, _InputIterator __last)
        ^
/opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/../../../../include/c++/12.2.0/bits/stl_map.h:238:7: note: candidate template ignored: could not match 'initializer_list' against 'pair'
      map(initializer_list<value_type> __l,
      ^
/opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/../../../../include/c++/12.2.0/bits/stl_map.h:250:7: note: candidate template ignored: could not match 'map' against 'pair'
      map(const map& __m, const __type_identity_t<allocator_type>& __a)
      ^
/opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/../../../../include/c++/12.2.0/bits/stl_map.h:254:7: note: candidate template ignored: could not match 'map' against 'pair'
      map(map&& __m, const __type_identity_t<allocator_type>& __a)
      ^
/opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/../../../../include/c++/12.2.0/bits/stl_map.h:260:7: note: candidate template ignored: could not match 'initializer_list' against 'pair'
      map(initializer_list<value_type> __l, const allocator_type& __a)
      ^
/opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/../../../../include/c++/12.2.0/bits/stl_map.h:1472:5: note: candidate template ignored: substitution failure [with _InputIterator = std::pair<const char *, int>]: no member named 'value_type' in 'std::iterator_traits<std::pair<const char *, int>>'
    map(_InputIterator, _InputIterator,
    ^
/opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/../../../../include/c++/12.2.0/bits/stl_map.h:1481:5: note: candidate template ignored: could not match 'initializer_list' against 'pair'
    map(initializer_list<pair<_Key, _Tp>>,
    ^
/opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/../../../../include/c++/12.2.0/bits/stl_map.h:1494:5: note: candidate template ignored: could not match 'initializer_list' against 'pair'
    map(initializer_list<pair<_Key, _Tp>>, _Allocator)
    ^
/opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/../../../../include/c++/12.2.0/bits/stl_map.h:217:7: note: candidate function template not viable: requires 1 argument, but 2 were provided
      map(const map&) = default;
      ^
/opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/../../../../include/c++/12.2.0/bits/stl_map.h:225:7: note: candidate function template not viable: requires 1 argument, but 2 were provided
      map(map&&) = default;
      ^
/opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/../../../../include/c++/12.2.0/bits/stl_map.h:246:7: note: candidate function template not viable: requires single argument '__a', but 2 arguments were provided
      map(const allocator_type& __a)
      ^
/opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/../../../../include/c++/12.2.0/bits/stl_map.h:100:11: note: candidate function template not viable: requires 1 argument, but 2 were provided
    class map
          ^
/opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/../../../../include/c++/12.2.0/bits/stl_map.h:266:2: note: candidate function template not viable: requires 3 arguments, but 2 were provided
        map(_InputIterator __first, _InputIterator __last,
        ^
/opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/../../../../include/c++/12.2.0/bits/stl_map.h:1488:5: note: candidate function template not viable: requires 3 arguments, but 2 were provided
    map(_InputIterator, _InputIterator, _Allocator)
    ^
/opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/../../../../include/c++/12.2.0/bits/stl_map.h:195:7: note: candidate function template not viable: requires 0 arguments, but 2 were provided
      map() = default;
      ^
/opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/../../../../include/c++/12.2.0/bits/stl_map.h:300:2: note: candidate function template not viable: requires at least 3 arguments, but 2 were provided
        map(_InputIterator __first, _InputIterator __last,
        ^
1 error generated.
Compiler returned: 1

Note both gcc/MSVC accept: https://godbolt.org/z/6v4fvabb5

self-assigned this
on Jul 5, 2023
added a commit that references this issue on Jun 18, 2024
f80bd9b

2 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

c++20clang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second party

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @yuanfang-chen@shafik@EugeneZelenko@llvmbot@walge-laine

    Issue actions

      Clang issue in CTAD · Issue #62925 · llvm/llvm-project