Bug 117114 - [15 Regression] -Woverloaded-virtual false positives on multiple inheritance since r15-4282-g60163c85730e6b
Summary: [15 Regression] -Woverloaded-virtual false positives on multiple inheritance ...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 15.0
: P3 normal
Target Milestone: 15.0
Assignee: Simon Martin
URL:
Keywords: build, diagnostic
: 117117 (view as bug list)
Depends on:
Blocks: 109918
  Show dependency treegraph
 
Reported: 2024-10-13 10:15 UTC by Sergei Trofimovich
Modified: 2025-02-04 10:02 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2024-10-13 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sergei Trofimovich 2024-10-13 10:15:05 UTC
Noticed the warnings and -Werror build failures on today's gcc-master from r15-4297-gc38385ddbcce9f.

Self-contained example extracted from fheroes2:

// $ cat bug.cc
struct Troops { virtual ~Troops(); };
struct Control { virtual int GetControl() const = 0; };
struct Army : Troops, Control { int GetControl() const override; };

$ g++ -c bug.cc -Woverloaded-virtual
bug.cc:2:30: warning: 'virtual int Control::GetControl() const' was hidden [-Woverloaded-virtual=]
    2 | struct Control { virtual int GetControl() const = 0; };
      |                              ^~~~~~~~~~
bug.cc:3:37: note:   by 'virtual int Army::GetControl() const'
    3 | struct Army : Troops, Control { int GetControl() const override; };
      |                                     ^~~~~~~~~~

$ g++ -v
Using built-in specs.
COLLECT_GCC=/<<NIX>>/gcc-15.0.0/bin/g++
COLLECT_LTO_WRAPPER=/<<NIX>>/gcc-15.0.0/libexec/gcc/x86_64-unknown-linux-gnu/15.0.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../source/configure --prefix=/<<NIX>>/gcc-15.0.0 --with-gmp-include=/<<NIX>>/gmp-6.3.0-dev/include --with-gmp-lib=/<<NIX>>/gmp-6.3.0/lib --with-mpfr-include=/<<NIX>>/mpfr-4.2.1-dev/include --with-mpfr-lib=/<<NIX>>/mpfr-4.2.1/lib --with-mpc=/<<NIX>>/libmpc-1.3.1 --with-native-system-header-dir=/<<NIX>>/glibc-2.40-36-dev/include --with-build-sysroot=/ --with-gxx-include-dir=/<<NIX>>/gcc-15.0.0/include/c++/15.0.0/ --program-prefix= --enable-lto --disable-libstdcxx-pch --without-included-gettext --with-system-zlib --enable-checking=release --enable-static --enable-languages=c,c++ --disable-multilib --enable-plugin --disable-libcc1 --with-isl=/<<NIX>>/isl-0.20 --disable-bootstrap --build=x86_64-unknown-linux-gnu --host=x86_64-unknown-linux-gnu --target=x86_64-unknown-linux-gnu
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 15.0.0 99999999 (experimental) (GCC)
Comment 1 Iain Sandoe 2024-10-13 10:23:29 UTC
most likely r15-4282-g60163c85730e6b7c56

this causes --languages=all bootstrap to fail when rust is included many many instances like:

/src-local/gcc-master/gcc/rust/ast/rust-ast.h:161:26: error: ‘virtual Rust::AST::MacroMatch::MacroMatchType Rust::AST::MacroMatch::get_macro_match_type() const’ was hidden [-Werror=overloaded-virtual=]
  161 |   virtual MacroMatchType get_macro_match_type () const = 0;
Comment 2 Sergei Trofimovich 2024-10-13 10:32:31 UTC
Yeah, gcc bisect agrees: landed on r15-4282-g60163c85730e6b.
Comment 3 Simon Martin 2024-10-13 10:52:11 UTC
Sorry for the breakage. Triggering a rust build and will advise about next steps.
Comment 4 Simon Martin 2024-10-13 11:56:36 UTC
Submitted https://gcc.gnu.org/pipermail/gcc-patches/2024-October/665222.html to restore the rust front-end build.
Comment 5 Sam James 2024-10-13 13:58:46 UTC
*** Bug 117117 has been marked as a duplicate of this bug. ***
Comment 6 Simon Martin 2024-10-13 16:02:16 UTC
The patch I mentioned above did not pass regtest so I have reverted the offending commit for the moment; commit r15-4301-ga4eec6c712ec16 refers.
Comment 7 Simon Martin 2024-10-13 16:09:39 UTC
Resolving. Apologies for the fallout :-/
Comment 8 GCC Commits 2025-02-04 10:02:52 UTC
The master branch has been updated by Simon Martin <simartin@gcc.gnu.org>:

https://gcc.gnu.org/g:d346af2af88caf1e21a5cc1f0afa33596198fb60

commit r15-7350-gd346af2af88caf1e21a5cc1f0afa33596198fb60
Author: Simon Martin <simon@nasilyan.com>
Date:   Tue Feb 4 10:58:17 2025 +0100

    c++: Fix overeager Woverloaded-virtual with conversion operators [PR109918]
    
    We currently emit an incorrect -Woverloaded-virtual warning upon the
    following test case
    
    === cut here ===
    struct A {
      virtual operator int() { return 42; }
      virtual operator char() = 0;
    };
    struct B : public A {
      operator char() { return 'A'; }
    };
    === cut here ===
    
    The problem is that when iterating over ovl_range (fns), warn_hidden
    gets confused by the conversion operator marker, concludes that
    seen_non_override is true and therefore emits a warning for all
    conversion operators in A that do not convert to char, even if
    -Woverloaded-virtual is 1 (e.g. with -Wall, the case reported).
    
    A second set of problems is highlighted when -Woverloaded-virtual is 2.
    
    First, with the same test case, since base_fndecls contains all
    conversion operators in A (except the one to char, that's been removed
    when iterating over ovl_range (fns)), we emit a spurious warning for
    the conversion operator to int, even though it's unrelated.
    
    Second, in case there are several conversion operators with different
    cv-qualifiers to the same type in A, we rightfully emit a warning,
    however the note uses the location of the conversion operator marker
    instead of the right one; location_of should go over conv_op_marker.
    
    This patch fixes all these by explicitly keeping track of (1) base
    methods that are overriden, as well as (2) base methods that are hidden
    but not overriden (and by what), and warning about methods that are in
    (2) but not (1). It also ignores non virtual base methods, per
    "definition" of -Woverloaded-virtual.
    
    Co-authored-by: Jason Merrill <jason@redhat.com>
    
            PR c++/117114
            PR c++/109918
    
    gcc/cp/ChangeLog:
    
            * class.cc (warn_hidden): Keep track of overloaded and of hidden
            base methods.
            * error.cc (location_of): Skip over conv_op_marker.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/warn/Woverloaded-virt1.C: Check that no warning is
            emitted for non virtual base methods.
            * g++.dg/warn/Woverloaded-virt10.C: New test.
            * g++.dg/warn/Woverloaded-virt11.C: New test.
            * g++.dg/warn/Woverloaded-virt12.C: New test.
            * g++.dg/warn/Woverloaded-virt13.C: New test.
            * g++.dg/warn/Woverloaded-virt5.C: New test.
            * g++.dg/warn/Woverloaded-virt6.C: New test.
            * g++.dg/warn/Woverloaded-virt7.C: New test.
            * g++.dg/warn/Woverloaded-virt8.C: New test.
            * g++.dg/warn/Woverloaded-virt9.C: New test.