Bug 110970 - clang / c++23 missing 'typename' prior to dependent type name 'iterator_traits<_It>::iterator_category'
Summary: clang / c++23 missing 'typename' prior to dependent type name 'iterator_trait...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 13.2.1
: P3 normal
Target Milestone: 13.3
Assignee: Jonathan Wakely
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2023-08-10 09:52 UTC by gcc-bugzilla
Modified: 2023-08-11 15:37 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2023-08-10 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description gcc-bugzilla 2023-08-10 09:52:43 UTC
Using clang with the current libstdc++ and c++23 (2b) fails:

echo "#include <algorithm>" | clang++ -std=c++2b -stdlib=libstdc++ -c -x c++ -
In file included from <stdin>:1:
In file included from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../include/c++/13.2.1/algorithm:60:
In file included from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../include/c++/13.2.1/bits/stl_algobase.h:67:
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../include/c++/13.2.1/bits/stl_iterator.h:2618:35: error: missing 'typename' prior to dependent type name 'iterator_traits<_It>::iterator_category'
      { using iterator_category = iterator_traits<_It>::iterator_category; };


The line is unchanged in the current git, so I presume this is not fixed yet.

Simply adding `typename` to the line does fix the issue with clang.

This is similar to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100900. I won't try to language lawyer what is technically correct here. In the other issue it was decided to be nice and support other implementations even though it is a (very low cost) workaround.
Comment 1 Jonathan Wakely 2023-08-10 12:29:18 UTC
Clang 15, I assume?
Comment 2 gcc-bugzilla 2023-08-10 12:36:17 UTC
Yes, apologies for the missing information

clang version 15.0.7
g++ (GCC) 13.2.1 20230801
(Arch)

According to https://clang.llvm.org/cxx_status.html
P0634R3 / "Down with typename!" is implemented since Clang 16 (released in March). So maybe this is actually not a problem for much longer. Might only affect the combination of a very recent GCC with slightly outdated Clang.
Comment 3 Jonathan Wakely 2023-08-10 12:55:26 UTC
We aim to support at least two versions of Clang, so we have to wait for 17 before we can consider 15 too old. That said, the combination of the newest -std and not-the-latest Clang is usually going to be a bit risky.

Anyway, I have a patch to fix this, which also cleans the code up a little.
Comment 4 GCC Commits 2023-08-10 22:32:22 UTC
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:

https://gcc.gnu.org/g:9cb2a7c8d54b1f6685bc509a07104c458262cb9f

commit r14-3134-g9cb2a7c8d54b1f6685bc509a07104c458262cb9f
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Aug 10 13:48:48 2023 +0100

    libstdc++: Use alias template for iterator_category [PR110970]
    
    This renames __iterator_category_t to __iter_category_t, for consistency
    with std::iter_value_t, std::iter_difference_t and std::iter_reference_t
    in C++20. Then use __iter_category_t in <bits/stl_iterator.h>, which
    fixes the problem of the missing 'typename' that Clang 15 incorrectly
    still requires.
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/110970
            * include/bits/stl_iterator.h (__detail::__move_iter_cat): Use
            __iter_category_t.
            (iterator_traits<common_iterator<I, S>>::_S_iter_cat): Likewise.
            (__detail::__basic_const_iterator_iter_cat): Likewise.
            * include/bits/stl_iterator_base_types.h (__iterator_category_t):
            Rename to __iter_category_t.
Comment 5 GCC Commits 2023-08-11 15:36:52 UTC
The releases/gcc-13 branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:

https://gcc.gnu.org/g:2e094543715fbd1a5486d77dcbfeec52d86aba61

commit r13-7710-g2e094543715fbd1a5486d77dcbfeec52d86aba61
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Aug 10 13:48:48 2023 +0100

    libstdc++: Use alias template for iterator_category [PR110970]
    
    This renames __iterator_category_t to __iter_category_t, for consistency
    with std::iter_value_t, std::iter_difference_t and std::iter_reference_t
    in C++20. Then use __iter_category_t in <bits/stl_iterator.h>, which
    fixes the problem of the missing 'typename' that Clang 15 incorrectly
    still requires.
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/110970
            * include/bits/stl_iterator.h (__detail::__move_iter_cat): Use
            __iter_category_t.
            (iterator_traits<common_iterator<I, S>>::_S_iter_cat): Likewise.
            (__detail::__basic_const_iterator_iter_cat): Likewise.
            * include/bits/stl_iterator_base_types.h (__iterator_category_t):
            Rename to __iter_category_t.
    
    (cherry picked from commit 9cb2a7c8d54b1f6685bc509a07104c458262cb9f)
Comment 6 Jonathan Wakely 2023-08-11 15:37:34 UTC
Fixed for 13.3, thanks for the report.