https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124604

            Bug ID: 124604
           Summary: [C++20] cp_preserve_using_decl = true causes parse
                    errors in libstdc++ <bits/iterator_concepts.h>
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kachalenko.denis at gmail dot com
  Target Milestone: ---

Created attachment 64000
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=64000&action=edit
Preprocessed source from `g++ -v -save-temps -std=c++20
-fplugin=./minimal_bug.dll -fsyntax-only bug_test.cpp` (GCC 16.0.1 20260319
trunk, x86_64-w64-mingw32). Original test case: `#include <bits/iter

GCC version (gcc -v):

gcc version 16.0.1 20260319 (experimental) (GCC) 
Target: x86_64-w64-mingw32
Configured with: ../gcc-source/configure --prefix=/home/kacha/gcc-trunk-install
--build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32
--target=x86_64-w64-mingw32 --enable-languages=c,c++ --enable-threads=mcf
--enable-shared --enable-static --enable-lto --enable-plugin
--enable-checking=release --disable-multilib --disable-nls --disable-werror
--disable-bootstrap --with-tune=native --with-system-zlib --with-zstd
Thread model: mcf


System type: x86_64-w64-mingw32 (MSYS2 UCRT64, Windows 11)


Complete command line that triggers the bug:

g++ -v -save-temps -std=c++20 -fplugin=./minimal_bug.dll -fsyntax-only
bug_test.cpp


Compiler output (full error):

In file included from bug_test.cpp:1:
bits/iterator_concepts.h:624:76: error: expected primary-expression before '>'
token
  624 |         requires
__detail::__is_signed_integer_like<iter_difference_t<_Iter>>;
      |                                                                        
   ^~
bits/iterator_concepts.h:624:78: error: expected primary-expression before ';'
token
  624 |         requires
__detail::__is_signed_integer_like<iter_difference_t<_Iter>>;
      |                                                                        
     ^
bits/iterator_concepts.h:998:67: error: expected primary-expression before '>'
token
  998 |       concept __adl_begin = __class_or_enum<remove_reference_t<_Tp>>
      |                                                                   ^~
bits/iterator_concepts.h:999:12: error: expected identifier before 'requires'
  999 |         && requires(_Tp& __t)
      |            ^~~~~~~~


Minimal plugin (plugin.cpp):

#include "gcc-plugin.h"
#include "cp/cp-tree.h"
#include "plugin-version.h"
int plugin_is_GPL_compatible;
int plugin_init(struct plugin_name_args*, struct plugin_gcc_version*) {
  cp_preserve_using_decl = true;
  return 0;
}


Minimal test case (bug_test.cpp):

#include <bits/iterator_concepts.h>


Build the plugin:

g++ -I$(g++ -print-file-name=plugin)/include -shared -fno-rtti -o
minimal_bug.dll plugin.cpp <cc1plus-import-lib>


Expected result: Compiles without errors (same as without -fplugin).
Actual result: Parse errors in libstdc++ requires clauses as shown above.


Differential testing:

 - Without -fplugin: OK
 - With -std=c++17 + -fplugin: OK (no concepts)
 - With -std=c++20 + -fplugin but cp_preserve_using_decl = false: OK


The preserved (unresolved) USING_DECL nodes appear to interfere with name
lookup inside requires clauses in <bits/iterator_concepts.h>.

Preprocessed source attached: a-bug_test.ii (generated via -save-temps)

Reply via email to