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

            Bug ID: 128681
           Summary: [modules] Partial specialization ignored for type used
                    through imported alias
           Product: gcc
           Version: 16.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: webtemp at gmail dot com
  Target Milestone: ---

Created attachment 66143
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=66143&action=edit
Another test case showing the same bug, with a build.sh

GCC picks the wrong template when I use a type through an alias from another
module.
The type has a partial specialization. GCC uses the primary template instead.

There are three files. None of them include anything.

a.cppm:

export module a;
import std;
export using BoolVector = std::vector<bool>;

b.cppm:

export module b;
import std;
import a;
void f(BoolVector &v) {
  v[0] = true;
  v.flip();
}

Commands:

g++ -std=c++23 -fmodules -fsearch-include-path -c bits/std.cc
g++ -std=c++23 -fmodules -c a.cppm
g++ -std=c++23 -fmodules -c b.cppm

Error from the last command:

b.cppm: In function 'void f(BoolVector@a&)':
b.cppm:6:5: error: 'using BoolVector = class std::vector<bool>' {aka 'class
std::vector<bool>'} has no member named 'flip'
    6 |   v.flip();
      |     ^~~~

std::vector<bool> should use the vector<bool> specialization, which has flip().
If I remove the line "v[0] = true;", it compiles.
So the call to v[0] seems to make GCC use the primary vector<T> template.
Clang 23 compiles both files with no error.

How I found it:
I hit this with std::vector<bool> and "import std;".
I had "using BoolVector = std::vector<bool>;" in one module.
In another module I used it as a function parameter and called operator[].
GCC used the primary vector<T> with T = bool, not the vector<bool>
specialization.
That object file reserved 24 bytes on the stack for the vector. The real
vector<bool> is 40 bytes.
Another object file had the correct vector<bool> code.
At link time the correct constructor was picked, and it wrote past the 24
bytes.
The program crashed with "*** stack smashing detected ***".
AddressSanitizer reported a stack-buffer-overflow in the vector<bool>
constructor.

The preprocessed files are the same as the sources. They only add the usual "#
0" line markers.

gcc -v:

Using built-in specs.
COLLECT_GCC=/usr/bin/g++
Target: x86_64-pc-linux-gnu
Configured with: ../gcc/configure
--enable-languages=ada,c,c++,d,fortran,go,lto,m2,objc,obj-c++,rust,cobol
--enable-bootstrap --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib
--mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://gitlab.archlinux.org/archlinux/packaging/packages/gcc/-/issues
--with-build-config=bootstrap-lto --with-gcc-major-version-only
--with-linker-hash-style=gnu --with-system-zlib --enable-cet=auto
--enable-checking=release --enable-clocale=gnu --enable-default-pie
--enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object
--enable-libstdcxx-backtrace --enable-link-serialization=1
--enable-linker-build-id --enable-lto --enable-multilib --enable-plugin
--enable-shared --enable-threads=posix --disable-fixincludes --disable-libssp
--disable-libstdcxx-pch --disable-werror
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 16.2.1 20260810 (GCC)

System: Arch Linux x86_64, package gcc 16.2.1+r23+gd564253eb6c8-1.
Linux exarch 7.2.14-zen1-1-zen #1 ZEN SMP PREEMPT_DYNAMIC Fri, 30 Oct 2026
14:32:44 +0000 x86_64 GNU/Linux

I have not tested trunk !

My first ever bug report so please go easy on me. I'm learning C++23 and
re-learning graphs and algorithms. Hit the original bug with a DFS
implementation with a std::vector<bool>& ...

Reply via email to