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

            Bug ID: 117825
           Summary: ICE on template with -Wformat-security (error
                    reporting routines re-entered.)
           Product: gcc
           Version: 14.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: marcus.haehnel at kernkonzept dot com
  Target Milestone: ---

When compiling this minimal example with gcc 12.2, 12.4, 14.2.1 or trunk (or
really any version I tried on Godbolt) I get an ICE (tried on x86_64 and
arm64).

--- ice.cc ---

__attribute__((format(printf, 1, 2)))
int fails(const char *, ...) { return 0; }

int works(const char *, ...) { return 0; }

template<auto func, typename...  Args>
auto wrap(Args... args) -> decltype(func(args...))
{
  return func(args...);
}


int main() {
    wrap<fails>("Test!");
}

---

I minimized the code as far as possible to not include any headers.
Compile with: `g++ ice.cc -Wformat-security -Wformat`

Replacing the template instantiation with the works instead of the fails
function does not produce an ICE. Using -Wno-format-security will also not
produce the ICE.



ICE/Compile output (on gcc 14.2.1):

---
ice.cc: In substitution of ‘template<auto func, class ... Args> decltype
(func(wrap::args ...)) wrap(Args ...) [with auto func = fails; Args = {const
char*}]’:
ice.cc:14:16:   required from here
   14 |     wrap<fails>("Test!");
      |     ~~~~~~~~~~~^~~~~~~~~
ice.cc:7:41: warning: format not a string literal and no format arguments
[-Wformat-security]
    7 | auto wrap(Args... args) -> decltype(func(args...))
      |                                     ~~~~^~~~~~~~~
‘
internal compiler error: error reporting routines re-entered.
0x558c53c9dd71 diagnostic_context::report_diagnostic(diagnostic_info*)
        ???:0
0x558c53ca1674 warning_at(unsigned int, int, char const*, ...)
        ???:0
0x558c5257460c check_function_format(tree_node const*, tree_node*, int,
tree_node**, vec<unsigned int, va_heap, vl_ptr>*)
        ???:0
0x558c52565123 check_function_arguments(unsigned int, tree_node const*,
tree_node const*, int, tree_node**, vec<unsigned int, va_heap, vl_ptr>*)
        ???:0
0x558c5251d141 cp_build_function_call_vec(tree_node*, vec<tree_node*, va_gc,
vl_embed>**, int, tree_node*)
        ???:0
0x558c524db47a finish_call_expr(tree_node*, vec<tree_node*, va_gc, vl_embed>**,
bool, bool, int)
        ???:0
0x558c524a6c51 tsubst_expr(tree_node*, tree_node*, int, tree_node*)
        ???:0
0x558c524ab7f3 tsubst(tree_node*, tree_node*, int, tree_node*)
        ???:0
0x558c53cb1cab pp_format(pretty_printer*, text_info*, urlifier const*)
        ???:0
0x558c53cb3721 pp_verbatim(pretty_printer*, char const*, ...)
        ???:0
0x558c53c9dbc4 diagnostic_context::report_diagnostic(diagnostic_info*)
        ???:0
0x558c53ca1674 warning_at(unsigned int, int, char const*, ...)
        ???:0
0x558c5257460c check_function_format(tree_node const*, tree_node*, int,
tree_node**, vec<unsigned int, va_heap, vl_ptr>*)
        ???:0
0x558c52565123 check_function_arguments(unsigned int, tree_node const*,
tree_node const*, int, tree_node**, vec<unsigned int, va_heap, vl_ptr>*)
        ???:0
0x558c5251d141 cp_build_function_call_vec(tree_node*, vec<tree_node*, va_gc,
vl_embed>**, int, tree_node*)
        ???:0
0x558c524db47a finish_call_expr(tree_node*, vec<tree_node*, va_gc, vl_embed>**,
bool, bool, int)
        ???:0
0x558c524a6c51 tsubst_expr(tree_node*, tree_node*, int, tree_node*)
        ???:0
0x558c524b296e instantiate_decl(tree_node*, bool, bool)
        ???:0
0x558c524c7af3 instantiate_pending_templates(int)
        ???:0
0x558c523a57a1 c_parse_final_cleanups()
        ???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
---

These gcc -v details are for my machine. Try any other on godbolt to get the
same error.

---
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/14/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with:
/var/tmp/notmpfs/portage/sys-devel/gcc-14.2.1_p20240817/work/gcc-14-20240817/configure
--host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --prefix=/usr
--bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/14
--includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/14/include
--datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/14
--mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/14/man
--infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/14/info
--with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/14/include/g++-v14
--disable-silent-rules --disable-dependency-tracking
--with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/14/python
--enable-languages=c,c++,fortran --enable-obsolete --enable-secureplt
--disable-werror --with-system-zlib --enable-nls --without-included-gettext
--disable-libunwind-exceptions --enable-checking=release
--with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo
14.2.1_p20240817 p4' --with-gcc-major-version-only --enable-libstdcxx-time
--enable-lto --disable-libstdcxx-pch --enable-shared --enable-threads=posix
--enable-__cxa_atexit --enable-clocale=gnu --enable-multilib
--with-multilib-list=m32,m64 --disable-fixed-point --enable-targets=all
--enable-libgomp --disable-libssp --disable-libada --disable-cet
--disable-systemtap --disable-valgrind-annotations --disable-vtable-verify
--disable-libvtv --without-zstd --with-isl --disable-isl-version-check
--enable-default-pie --enable-host-pie --disable-host-bind-now
--enable-default-ssp --disable-fixincludes
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.2.1 20240817 (Gentoo 14.2.1_p20240817 p4) 
---

Godbolt: https://godbolt.org/z/j666o4z5e

Reply via email to