Bug 111790 - [12/13/14/15 Regression] Unwarranted missing template keyword warning
Summary: [12/13/14/15 Regression] Unwarranted missing template keyword warning
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 12.0
: P2 normal
Target Milestone: 12.5
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2023-10-12 16:37 UTC by Tinko Sebastian Bartels
Modified: 2024-06-20 09:14 UTC (History)
5 users (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tinko Sebastian Bartels 2023-10-12 16:37:35 UTC
Consider the following code:

template <typename T> //no warning if this is not a template
struct X
{
    T v;
};

template <typename T>
inline void f() {
    X<T> x; //no warning with e.g. X<int>
    if(x.v < 0 && 
       0 > -1) {} //No warning without the "-"
}

int main() {
    f<int>(); //Still get a warning without this instantiation.
}

GCC 12, 13, current trunk and seemingly everything after b8ffa71e427 give me a warning for this:
warning: expected 'template' keyword before dependent template name [-Wmissing-template-keyword]

But GCC compiles it, so it seems to interpret it correctly at some point after triggering the warning. I tried to look into it and thought that maybe 

cp_lexer_peek_token (parser->lexer)->type
	      <= CPP_LAST_PUNCTUATOR

in line 6447 of gcc/cp/parser.cc is too general but I do not have a proposed patch.
Comment 1 Tinko Sebastian Bartels 2023-10-12 16:42:30 UTC
A command line that can trigger the behavior is

g++ main.cpp

One of the versions for which it occurs is

g++ -v
Es werden eingebaute Spezifikationen verwendet.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/lto-wrapper
Ziel: x86_64-pc-linux-gnu
Konfiguriert mit: /build/gcc/src/gcc/configure --enable-languages=ada,c,c++,d,fortran,go,lto,objc,obj-c++ --enable-bootstrap --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --with-build-config=bootstrap-lto --with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit --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-libssp --disable-libstdcxx-pch --disable-werror
Thread-Modell: posix
Unterstützte LTO-Kompressionsalgorithmen: zlib zstd
gcc-Version 13.2.1 20230801 (GCC)
Comment 2 Patrick Palka 2023-10-16 23:29:42 UTC
Confirmed.
Comment 3 Marek Polacek 2024-02-01 23:25:28 UTC
Started with r12-6563-gb8ffa71e4271ae:

commit b8ffa71e4271ae562c2d315b9b24c4979bbf8227
Author: Anthony Sharp <anthonysharp15@gmail.com>
Date:   Sat Dec 4 17:23:22 2021 +0000

    c++: warning for dependent template members [PR70417]


But is seems to me this is the case of a false positive
<https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wmissing-template-keyword>
talks about.  Wrapping "x.v < 0" in () suppresses the warning.
Comment 4 Richard Biener 2024-06-20 09:14:12 UTC
GCC 12.4 is being released, retargeting bugs to GCC 12.5.