public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/107461] New: GCC rejects program with ambiguity error
@ 2022-10-30  8:17 jlame646 at gmail dot com
  2022-10-30 19:13 ` [Bug c++/107461] " pinskia at gcc dot gnu.org
                   ` (17 more replies)
  0 siblings, 18 replies; 19+ messages in thread
From: jlame646 at gmail dot com @ 2022-10-30  8:17 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 107461
           Summary: GCC rejects program with ambiguity error
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jlame646 at gmail dot com
  Target Milestone: ---

The following well-formed program(afaik) is rejected by gcc but accepted by
clang and msbc. Demo: https://godbolt.org/z/bMWxd8bEa

```
#include <iostream>
#include <type_traits>
#include <vector>
#include <string>
#include <functional>
#include <map>
#include <algorithm>
using namespace std;
#include <algorithm>
#include <array>
#include <type_traits>
#include <vector>

namespace MLL{
  template<typename data_t, std::size_t n_rows, std::size_t n_cols, std::size_t
MAX=256>
    class Matrix;    //this forward declaration not needed but you can have
this if you want and if you do then make sure that you only provide the default
arg 256 in declaration and not in definition
//--------------------------------------------------------------------------------vvvvvvv---->added
this default arg here instead of in forward declaration
    template<typename data_t, std::size_t n_rows, std::size_t n_cols,
std::size_t MAX>
    class Matrix{
        static constexpr bool IS_STATIC = n_rows * n_cols <= MAX;
        using container_t = typename std::conditional<IS_STATIC,
std::array<data_t, n_rows * n_cols>, std::vector<data_t>>::type;

        container_t m_data_list;

    public:
        Matrix(){
            if constexpr( !IS_STATIC ){
                m_data_list.resize(n_rows * n_cols);
            }
        }

        explicit Matrix(data_t default_value){
            if constexpr( IS_STATIC ){
                m_data_list.fill(default_value);
            }else{
                m_data_list.resize(n_rows * n_cols, default_value);
            }
        }

        explicit Matrix(std::initializer_list<data_t>&& value_list){
            std::copy(value_list.begin(), value_list.end(),
m_data_list.begin());
        }

        Matrix(Matrix const& other)
                : m_data_list(other.m_data_list){
        }

        Matrix(Matrix&& other) noexcept
                : m_data_list(std::move(other.m_data_list)){
        }

        Matrix& operator=(Matrix const& other){
            m_data_list = other.m_data_list;
            return *this;
        }

        Matrix& operator=(Matrix&& other) noexcept{
            m_data_list = std::move(other.m_data_list);
            return *this;
        }

        //renamed all the arguments by prefexing them with OP for better
readibility
        template<typename data_tOP, typename TOP, std::size_t n_rowst,
std::size_t n_colsOP, std::size_t MAXOP, std::size_t other_MAXOP>
    friend Matrix<decltype(std::declval<data_tOP>() + std::declval<TOP>()),
n_rowst, n_colsOP, std::min(MAXOP, other_MAXOP)>
    operator+(Matrix<data_tOP, n_rowst, n_colsOP, MAXOP> const& lhs,
Matrix<TOP, n_rowst, n_colsOP, other_MAXOP> const& rhs);
    };

     template<typename data_tOP, typename TOP, std::size_t n_rowst, std::size_t
n_colsOP, std::size_t MAXOP, std::size_t other_MAXOP>
    Matrix<decltype(std::declval<data_tOP>() + std::declval<TOP>()), n_rowst,
n_colsOP, std::min(MAXOP, other_MAXOP)>
    operator+(Matrix<data_tOP, n_rowst, n_colsOP, MAXOP> const& lhs,
Matrix<TOP, n_rowst, n_colsOP, other_MAXOP> const& rhs){
         const std::size_t n = n_rowst * n_colsOP;
        for( std::size_t i = 0; i < n; ++i ){
           // lhs.m_data_list[i] += rhs.m_data_list[i];   //can't assing using
const lvalue reference
        }
        return lhs;
    }
}
int main()
{

    MLL::Matrix<int, 4, 4> a({1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16});
    a+a;
    return 0;;
}

```

GCC rejects this with the error:

```
<source>:82:6: error: ambiguous overload for 'operator+' (operand types are
'MLL::Matrix<int, 4, 4>' and 'MLL::Matrix<int, 4, 4>')
   82 |     a+a;
      |     ~^~
      |     | |
      |     | Matrix<[...],[...],[...]>
      |     Matrix<[...],[...],[...]>
<source>:70:5: note: candidate: 'MLL::Matrix<decltype ((declval<data_tOP>() +
declval<TOP>())), n_rowst, n_colsOP, std::min<long unsigned int>(MAXOP,
other_MAXOP)> MLL::operator+(const Matrix<data_tOP, n_rowst, n_colsOP, MAXOP>&,
const Matrix<TOP, n_rowst, n_colsOP, other_MAXOP>&) [with data_tOP = int; TOP =
int; long unsigned int n_rowst = 4; long unsigned int n_colsOP = 4; long
unsigned int MAXOP = 256; long unsigned int other_MAXOP = 256; decltype
((declval<data_tOP>() + declval<TOP>())) = int]'
   70 |     operator+(Matrix<data_tOP, n_rowst, n_colsOP, MAXOP> const& lhs,
Matrix<TOP, n_rowst, n_colsOP, other_MAXOP> const& rhs){
      |     ^~~~~~~~
<source>:65:5: note: candidate: 'MLL::Matrix<decltype ((declval<data_tOP>() +
declval<TOP>())), n_rowst, n_colsOP, std::min<long unsigned int>(MAXOP,
other_MAXOP)> MLL::operator+(const Matrix<data_tOP, n_rowst, n_colsOP, MAXOP>&,
const Matrix<TOP, n_rowst, n_colsOP, other_MAXOP>&) [with data_tOP = int; TOP =
int; long unsigned int n_rowst = 4; long unsigned int n_colsOP = 4; long
unsigned int MAXOP = 256; long unsigned int other_MAXOP = 256; data_t = int;
long unsigned int n_rows = 4; long unsigned int n_cols = 4; long unsigned int
MAX = 256; decltype ((declval<data_tOP>() + declval<TOP>())) = int]'
   65 |     operator+(Matrix<data_tOP, n_rowst, n_colsOP, MAXOP> const& lhs,
Matrix<TOP, n_rowst, n_colsOP, other_MAXOP> const& rhs);
      |     ^~~~~~~~
```

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [Bug c++/107461] GCC rejects program with ambiguity error
  2022-10-30  8:17 [Bug c++/107461] New: GCC rejects program with ambiguity error jlame646 at gmail dot com
@ 2022-10-30 19:13 ` pinskia at gcc dot gnu.org
  2022-11-08 14:19 ` [Bug c++/107461] [12/13 Regression] ambiguity error for friend with templated constexpr argument ppalka at gcc dot gnu.org
                   ` (16 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-10-30 19:13 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2022-10-30
     Ever confirmed|0                           |1

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed. reduced testcase:
template <class T> constexpr const T min(const T t0, const T t1) { return 0; }
template<int MAX>
struct Matrix{
    template<int MAXOP, int other_MAXOP>
friend Matrix<min(MAXOP, other_MAXOP)>
operator+(Matrix<MAXOP> const& lhs, Matrix<other_MAXOP> const& rhs);
};

template<int MAXOP, int other_MAXOP>
Matrix<min(MAXOP, other_MAXOP)>
operator+(Matrix<MAXOP> const& lhs, Matrix<other_MAXOP> const& rhs);

void f()
{
    Matrix<1> a;
    a+a;
}

---- CUT ----
Note the min function inside the return type is important and is looking like
is what is causing issues to not match the two decls to be the same.
Having min as a non-template function allows it to be matched.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [Bug c++/107461] [12/13 Regression] ambiguity error for friend with templated constexpr argument
  2022-10-30  8:17 [Bug c++/107461] New: GCC rejects program with ambiguity error jlame646 at gmail dot com
  2022-10-30 19:13 ` [Bug c++/107461] " pinskia at gcc dot gnu.org
@ 2022-11-08 14:19 ` ppalka at gcc dot gnu.org
  2023-01-13 11:37 ` rguenth at gcc dot gnu.org
                   ` (15 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-11-08 14:19 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |12.3
            Summary|ambiguity error for friend  |[12/13 Regression]
                   |with templated constexpr    |ambiguity error for friend
                   |argument                    |with templated constexpr
                   |                            |argument
      Known to work|                            |11.3.0
                 CC|                            |ppalka at gcc dot gnu.org
           Assignee|unassigned at gcc dot gnu.org      |ppalka at gcc dot gnu.org
      Known to fail|                            |12.2.0, 13.0
             Status|NEW                         |ASSIGNED

--- Comment #2 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Started with r12-6075-g2decd2cabe5a4f

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [Bug c++/107461] [12/13 Regression] ambiguity error for friend with templated constexpr argument
  2022-10-30  8:17 [Bug c++/107461] New: GCC rejects program with ambiguity error jlame646 at gmail dot com
  2022-10-30 19:13 ` [Bug c++/107461] " pinskia at gcc dot gnu.org
  2022-11-08 14:19 ` [Bug c++/107461] [12/13 Regression] ambiguity error for friend with templated constexpr argument ppalka at gcc dot gnu.org
@ 2023-01-13 11:37 ` rguenth at gcc dot gnu.org
  2023-02-03 14:41 ` cvs-commit at gcc dot gnu.org
                   ` (14 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-01-13 11:37 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [Bug c++/107461] [12/13 Regression] ambiguity error for friend with templated constexpr argument
  2022-10-30  8:17 [Bug c++/107461] New: GCC rejects program with ambiguity error jlame646 at gmail dot com
                   ` (2 preceding siblings ...)
  2023-01-13 11:37 ` rguenth at gcc dot gnu.org
@ 2023-02-03 14:41 ` cvs-commit at gcc dot gnu.org
  2023-02-03 15:07 ` [Bug c++/107461] [12 " cvs-commit at gcc dot gnu.org
                   ` (13 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-02-03 14:41 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:59e0376f607805ef9b67fd7b0a4a3084ab3571a5

commit r13-5684-g59e0376f607805ef9b67fd7b0a4a3084ab3571a5
Author: Patrick Palka <ppalka@redhat.com>
Date:   Fri Feb 3 09:41:10 2023 -0500

    c++: unexpected ADDR_EXPR after overload set pruning [PR107461]

    Here the ahead-of-time overload set pruning in finish_call_expr is
    unintentionally returning a CALL_EXPR whose (pruned) callee is wrapped
    in an ADDR_EXPR, despite the original callee not being wrapped in an
    ADDR_EXPR.  This ends up causing a bogus declaration mismatch error in
    the below testcase because the call to min in #1 gets expressed as a
    CALL_EXPR of ADDR_EXPR of FUNCTION_DECL, whereas the level-lowered call
    to min in #2 gets expressed instead as a CALL_EXPR of FUNCTION_DECL.

    This patch fixes this by stripping the spurious ADDR_EXPR appropriately.
    Thus the first call to min now also gets expressed as a CALL_EXPR of
    FUNCTION_DECL, matching the behavior before r12-6075-g2decd2cabe5a4f.

            PR c++/107461

    gcc/cp/ChangeLog:

            * semantics.cc (finish_call_expr): Strip ADDR_EXPR from
            the selected callee during overload set pruning.

    gcc/testsuite/ChangeLog:

            * g++.dg/template/call9.C: New test.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [Bug c++/107461] [12 Regression] ambiguity error for friend with templated constexpr argument
  2022-10-30  8:17 [Bug c++/107461] New: GCC rejects program with ambiguity error jlame646 at gmail dot com
                   ` (3 preceding siblings ...)
  2023-02-03 14:41 ` cvs-commit at gcc dot gnu.org
@ 2023-02-03 15:07 ` cvs-commit at gcc dot gnu.org
  2023-02-03 15:08 ` ppalka at gcc dot gnu.org
                   ` (12 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-02-03 15:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Patrick Palka
<ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:534aea1ca7e7538dc6af3eac3cd2ec6c7343fdee

commit r12-9103-g534aea1ca7e7538dc6af3eac3cd2ec6c7343fdee
Author: Patrick Palka <ppalka@redhat.com>
Date:   Fri Feb 3 09:41:10 2023 -0500

    c++: unexpected ADDR_EXPR after overload set pruning [PR107461]

    Here the ahead-of-time overload set pruning in finish_call_expr is
    unintentionally returning a CALL_EXPR whose (pruned) callee is wrapped
    in an ADDR_EXPR, despite the original callee not being wrapped in an
    ADDR_EXPR.  This ends up causing a bogus declaration mismatch error in
    the below testcase because the call to min in #1 gets expressed as a
    CALL_EXPR of ADDR_EXPR of FUNCTION_DECL, whereas the level-lowered call
    to min in #2 gets expressed instead as a CALL_EXPR of FUNCTION_DECL.

    This patch fixes this by stripping the spurious ADDR_EXPR appropriately.
    Thus the first call to min now also gets expressed as a CALL_EXPR of
    FUNCTION_DECL, matching the behavior before r12-6075-g2decd2cabe5a4f.

            PR c++/107461

    gcc/cp/ChangeLog:

            * semantics.cc (finish_call_expr): Strip ADDR_EXPR from
            the selected callee during overload set pruning.

    gcc/testsuite/ChangeLog:

            * g++.dg/template/call9.C: New test.

    (cherry picked from commit 59e0376f607805ef9b67fd7b0a4a3084ab3571a5)

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [Bug c++/107461] [12 Regression] ambiguity error for friend with templated constexpr argument
  2022-10-30  8:17 [Bug c++/107461] New: GCC rejects program with ambiguity error jlame646 at gmail dot com
                   ` (4 preceding siblings ...)
  2023-02-03 15:07 ` [Bug c++/107461] [12 " cvs-commit at gcc dot gnu.org
@ 2023-02-03 15:08 ` ppalka at gcc dot gnu.org
  2023-02-04  7:26 ` raj.khem at gmail dot com
                   ` (11 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-02-03 15:08 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #5 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 12.3/13, thanks for the bug report.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [Bug c++/107461] [12 Regression] ambiguity error for friend with templated constexpr argument
  2022-10-30  8:17 [Bug c++/107461] New: GCC rejects program with ambiguity error jlame646 at gmail dot com
                   ` (5 preceding siblings ...)
  2023-02-03 15:08 ` ppalka at gcc dot gnu.org
@ 2023-02-04  7:26 ` raj.khem at gmail dot com
  2023-02-04 10:37 ` jakub at gcc dot gnu.org
                   ` (10 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: raj.khem at gmail dot com @ 2023-02-04  7:26 UTC (permalink / raw)
  To: gcc-bugs

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

Khem Raj <raj.khem at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |raj.khem at gmail dot com

--- Comment #6 from Khem Raj <raj.khem at gmail dot com> ---
This is now resulting in build error in harfbuzz on aarch64 which did not
happen before, the testcase is here

https://uclibc.org/~kraj/hb-aat-layout.cc.i

Compile cmd used is

/mnt/b/cross/aarch64-linux-musl/tools/bin/aarch64-linux-musl-g++
--sysroot=/mnt/b/yoe/master/build/tmp/work/cortexa72-yoe-linux/harfbuzz/6.0.0-r0/recipe-sysroot
-fstack-protector-strong -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security
-Werror=format-security -Isrc/libharfbuzz.so.0.60600.0.p -Isrc
-I../harfbuzz-6.0.0/src -I. -I../harfbuzz-6.0.0 -fdiagnostics-color=always
-D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -std=c++11 -fno-rtti -fno-exceptions
-fno-rtti -fno-threadsafe-statics -fvisibility-inlines-hidden -DHAVE_CONFIG_H
-O2 -pipe -g -feliminate-unused-debug-types
-fmacro-prefix-map=/mnt/b/yoe/master/build/tmp/work/cortexa72-yoe-linux/harfbuzz/6.0.0-r0/harfbuzz-6.0.0=/usr/src/debug/harfbuzz/6.0.0-r0
-fdebug-prefix-map=/mnt/b/yoe/master/build/tmp/work/cortexa72-yoe-linux/harfbuzz/6.0.0-r0/harfbuzz-6.0.0=/usr/src/debug/harfbuzz/6.0.0-r0
-fmacro-prefix-map=/mnt/b/yoe/master/build/tmp/work/cortexa72-yoe-linux/harfbuzz/6.0.0-r0/build=/usr/src/debug/harfbuzz/6.0.0-r0
-fdebug-prefix-map=/mnt/b/yoe/master/build/tmp/work/cortexa72-yoe-linux/harfbuzz/6.0.0-r0/build=/usr/src/debug/harfbuzz/6.0.0-r0
-fdebug-prefix-map=/mnt/b/yoe/master/build/tmp/work/cortexa72-yoe-linux/harfbuzz/6.0.0-r0/recipe-sysroot=
-fmacro-prefix-map=/mnt/b/yoe/master/build/tmp/work/cortexa72-yoe-linux/harfbuzz/6.0.0-r0/recipe-sysroot=
-fdebug-prefix-map=/mnt/b/yoe/master/build/tmp/work/cortexa72-yoe-linux/harfbuzz/6.0.0-r0/recipe-sysroot-native=
-fvisibility-inlines-hidden -fPIC -pthread -Wno-non-virtual-dtor -MD -MQ
src/libharfbuzz.so.0.60600.0.p/hb-aat-layout.cc.o -MF
src/libharfbuzz.so.0.60600.0.p/hb-aat-layout.cc.o.d -o
src/libharfbuzz.so.0.60600.0.p/hb-aat-layout.cc.o -c
../harfbuzz-6.0.0/src/hb-aat-layout.cc

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [Bug c++/107461] [12 Regression] ambiguity error for friend with templated constexpr argument
  2022-10-30  8:17 [Bug c++/107461] New: GCC rejects program with ambiguity error jlame646 at gmail dot com
                   ` (6 preceding siblings ...)
  2023-02-04  7:26 ` raj.khem at gmail dot com
@ 2023-02-04 10:37 ` jakub at gcc dot gnu.org
  2023-02-04 10:39 ` jakub at gcc dot gnu.org
                   ` (9 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-02-04 10:37 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Reduced testcase:
template <typename T> T foo ();
template <typename> using A = int;
template <typename T, typename U>
auto operator| (T, U) -> decltype (U() (T()));
template <typename T> struct B {
  template <typename U, typename = A<decltype (foo<T> () (0, foo<typename U::E>
()))>>
  void operator() (U);
};
struct {
  template <typename T, typename U>
  B<T> operator() (T, U) { return B<T> (); }
} c;
struct D {
  D() {
    c([] {}, 0);
  }
  struct E {
  };
  void bar ()
  {
    E f;
    f | c ([] (int, E) {}, 0);
  }
};

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [Bug c++/107461] [12 Regression] ambiguity error for friend with templated constexpr argument
  2022-10-30  8:17 [Bug c++/107461] New: GCC rejects program with ambiguity error jlame646 at gmail dot com
                   ` (7 preceding siblings ...)
  2023-02-04 10:37 ` jakub at gcc dot gnu.org
@ 2023-02-04 10:39 ` jakub at gcc dot gnu.org
  2023-02-04 10:39 ` [Bug c++/107461] [12/13 " jakub at gcc dot gnu.org
                   ` (8 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-02-04 10:39 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|FIXED                       |---
             Status|RESOLVED                    |REOPENED

--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [Bug c++/107461] [12/13 Regression] ambiguity error for friend with templated constexpr argument
  2022-10-30  8:17 [Bug c++/107461] New: GCC rejects program with ambiguity error jlame646 at gmail dot com
                   ` (8 preceding siblings ...)
  2023-02-04 10:39 ` jakub at gcc dot gnu.org
@ 2023-02-04 10:39 ` jakub at gcc dot gnu.org
  2023-02-04 17:02 ` ppalka at gcc dot gnu.org
                   ` (7 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-02-04 10:39 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P2                          |P1
            Summary|[12 Regression] ambiguity   |[12/13 Regression]
                   |error for friend with       |ambiguity error for friend
                   |templated constexpr         |with templated constexpr
                   |argument                    |argument

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [Bug c++/107461] [12/13 Regression] ambiguity error for friend with templated constexpr argument
  2022-10-30  8:17 [Bug c++/107461] New: GCC rejects program with ambiguity error jlame646 at gmail dot com
                   ` (9 preceding siblings ...)
  2023-02-04 10:39 ` [Bug c++/107461] [12/13 " jakub at gcc dot gnu.org
@ 2023-02-04 17:02 ` ppalka at gcc dot gnu.org
  2023-02-04 17:04 ` ppalka at gcc dot gnu.org
                   ` (6 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-02-04 17:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from Patrick Palka <ppalka at gcc dot gnu.org> ---
(In reply to Jakub Jelinek from comment #7)
> Reduced testcase:

Interestingly Clang also rejects this testcase, so I'm not sure if we were
correct to accept it previously.

Here's a more reduced testcase that seems clearly valid:

template <typename T> T foo ();

template <typename> struct A { };

template <typename T> struct B {
  template <typename U, typename = A<decltype (foo<T>() (U()))>>
  static void bar(U);
};

int main() {
  B<int> b;
  B<void(*)(int)>::bar(0);
}

<stdin>: In function ‘int main()’:
<stdin>:12:23: error: no matching function for call to ‘B<void
(*)(int)>::bar(int)’
<stdin>:7:15: note: candidate: ‘template<class U, class> static void
B<T>::bar(U) [with <template-parameter-2-2> = U; T = void (*)(int)]’
<stdin>:7:15: note:   template argument deduction/substitution failed:
<stdin>:6:54: error: expression cannot be used as a function

If we remove the line #1 then this bogus error disappears.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [Bug c++/107461] [12/13 Regression] ambiguity error for friend with templated constexpr argument
  2022-10-30  8:17 [Bug c++/107461] New: GCC rejects program with ambiguity error jlame646 at gmail dot com
                   ` (10 preceding siblings ...)
  2023-02-04 17:02 ` ppalka at gcc dot gnu.org
@ 2023-02-04 17:04 ` ppalka at gcc dot gnu.org
  2023-02-04 17:14 ` jakub at gcc dot gnu.org
                   ` (5 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-02-04 17:04 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from Patrick Palka <ppalka at gcc dot gnu.org> ---
(In reply to Patrick Palka from comment #9)
> If we remove the line #1 then this bogus error disappears.

The line 'B<int> b;' rather.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [Bug c++/107461] [12/13 Regression] ambiguity error for friend with templated constexpr argument
  2022-10-30  8:17 [Bug c++/107461] New: GCC rejects program with ambiguity error jlame646 at gmail dot com
                   ` (11 preceding siblings ...)
  2023-02-04 17:04 ` ppalka at gcc dot gnu.org
@ 2023-02-04 17:14 ` jakub at gcc dot gnu.org
  2023-02-06  2:35 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-02-04 17:14 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #11 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to Patrick Palka from comment #9)
> (In reply to Jakub Jelinek from comment #7)
> > Reduced testcase:
> 
> Interestingly Clang also rejects this testcase, so I'm not sure if we were
> correct to accept it previously.

Note, the reduction was done purely with a test that it compiles without errors
before your commit and with 1-3 errors "no matching function for call to" after
it.
Another thing is whether harfbuzz full source is valid or not, but that might
be more difficult to find out because clang doesn't support the same
builtins/traits etc.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [Bug c++/107461] [12/13 Regression] ambiguity error for friend with templated constexpr argument
  2022-10-30  8:17 [Bug c++/107461] New: GCC rejects program with ambiguity error jlame646 at gmail dot com
                   ` (12 preceding siblings ...)
  2023-02-04 17:14 ` jakub at gcc dot gnu.org
@ 2023-02-06  2:35 ` cvs-commit at gcc dot gnu.org
  2023-02-06  3:01 ` ppalka at gcc dot gnu.org
                   ` (3 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-02-06  2:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #12 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:31924665c86d47af6b1f22a74f594f2e1dc0ed2d

commit r13-5707-g31924665c86d47af6b1f22a74f594f2e1dc0ed2d
Author: Patrick Palka <ppalka@redhat.com>
Date:   Sun Feb 5 21:35:33 2023 -0500

    c++: equivalence of non-dependent calls [PR107461]

    After r13-5684-g59e0376f607805 the (pruned) callee of a non-dependent
    CALL_EXPR is a bare FUNCTION_DECL rather than ADDR_EXPR of FUNCTION_DECL.
    This innocent change revealed that cp_tree_equal doesn't first check
    dependence of a CALL_EXPR before treating a FUNCTION_DECL callee as a
    dependent name, which leads to us incorrectly accepting the first two
    testcases below and rejecting the third:

     * In the first testcase, cp_tree_equal incorrectly returns true for
       the two non-dependent CALL_EXPRs f(0) and f(0) (whose CALL_EXPR_FN
       are different FUNCTION_DECLs) which causes us to treat #2 as a
       redeclaration of #1.

     * Same issue in the second testcase, for f<int*>() and f<char>().

     * In the third testcase, cp_tree_equal incorrectly returns true for
       f<int>() and f<void(*)(int)>() which causes us to conflate the two
       dependent specializations A<decltype(f<int>()(U()))> and
       A<decltype(f<void(*)(int)>()(U()))>.

    This patch fixes this by making called_fns_equal treat two callees as
    dependent names only if the overall CALL_EXPRs are dependent, via a new
    convenience function call_expr_dependent_name that is like dependent_name
    but also checks dependence of the overall CALL_EXPR.

            PR c++/107461

    gcc/cp/ChangeLog:

            * cp-tree.h (call_expr_dependent_name): Declare.
            * pt.cc (iterative_hash_template_arg) <case CALL_EXPR>: Use
            call_expr_dependent_name instead of dependent_name.
            * tree.cc (call_expr_dependent_name): Define.
            (called_fns_equal): Adjust to take two CALL_EXPRs instead of
            CALL_EXPR_FNs thereof.  Use call_expr_dependent_name instead
            of dependent_name.
            (cp_tree_equal) <case CALL_EXPR>: Adjust call to called_fns_equal.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp0x/overload5.C: New test.
            * g++.dg/cpp0x/overload5a.C: New test.
            * g++.dg/cpp0x/overload6.C: New test.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [Bug c++/107461] [12/13 Regression] ambiguity error for friend with templated constexpr argument
  2022-10-30  8:17 [Bug c++/107461] New: GCC rejects program with ambiguity error jlame646 at gmail dot com
                   ` (13 preceding siblings ...)
  2023-02-06  2:35 ` cvs-commit at gcc dot gnu.org
@ 2023-02-06  3:01 ` ppalka at gcc dot gnu.org
  2023-02-06 16:33 ` [Bug c++/107461] [12 " cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-02-06  3:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #13 from Patrick Palka <ppalka at gcc dot gnu.org> ---
hb-aat-layout.cc.i and the comment #9 test should be accepted on trunk again
now, backport to the 12 branch to follow.

The comment #7 testcase I think is invalid because GCC incorrectly accepts the
substitution 'typename U::E [with U=E]', which seems to be PR34810.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [Bug c++/107461] [12 Regression] ambiguity error for friend with templated constexpr argument
  2022-10-30  8:17 [Bug c++/107461] New: GCC rejects program with ambiguity error jlame646 at gmail dot com
                   ` (14 preceding siblings ...)
  2023-02-06  3:01 ` ppalka at gcc dot gnu.org
@ 2023-02-06 16:33 ` cvs-commit at gcc dot gnu.org
  2023-02-06 16:36 ` ppalka at gcc dot gnu.org
  2023-03-03 14:12 ` ppalka at gcc dot gnu.org
  17 siblings, 0 replies; 19+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-02-06 16:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #14 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Patrick Palka
<ppalka@gcc.gnu.org>:

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

commit r12-9110-geda24f6c12b6d3777ff3bf3656187e695a3e8dc2
Author: Patrick Palka <ppalka@redhat.com>
Date:   Sun Feb 5 21:35:33 2023 -0500

    c++: equivalence of non-dependent calls [PR107461]

    After r13-5684-g59e0376f607805 the (pruned) callee of a non-dependent
    CALL_EXPR is a bare FUNCTION_DECL rather than ADDR_EXPR of FUNCTION_DECL.
    This innocent change revealed that cp_tree_equal doesn't first check
    dependence of a CALL_EXPR before treating a FUNCTION_DECL callee as a
    dependent name, which leads to us incorrectly accepting the first two
    testcases below and rejecting the third:

     * In the first testcase, cp_tree_equal incorrectly returns true for
       the two non-dependent CALL_EXPRs f(0) and f(0) (whose CALL_EXPR_FN
       are different FUNCTION_DECLs) which causes us to treat #2 as a
       redeclaration of #1.

     * Same issue in the second testcase, for f<int*>() and f<char>().

     * In the third testcase, cp_tree_equal incorrectly returns true for
       f<int>() and f<void(*)(int)>() which causes us to conflate the two
       dependent specializations A<decltype(f<int>()(U()))> and
       A<decltype(f<void(*)(int)>()(U()))>.

    This patch fixes this by making called_fns_equal treat two callees as
    dependent names only if the overall CALL_EXPRs are dependent, via a new
    convenience function call_expr_dependent_name that is like dependent_name
    but also checks dependence of the overall CALL_EXPR.

            PR c++/107461

    gcc/cp/ChangeLog:

            * cp-tree.h (call_expr_dependent_name): Declare.
            * pt.cc (iterative_hash_template_arg) <case CALL_EXPR>: Use
            call_expr_dependent_name instead of dependent_name.
            * tree.cc (call_expr_dependent_name): Define.
            (called_fns_equal): Adjust to take two CALL_EXPRs instead of
            CALL_EXPR_FNs thereof.  Use call_expr_dependent_name instead
            of dependent_name.
            (cp_tree_equal) <case CALL_EXPR>: Adjust call to called_fns_equal.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp0x/overload5.C: New test.
            * g++.dg/cpp0x/overload5a.C: New test.
            * g++.dg/cpp0x/overload6.C: New test.

    (cherry picked from commit 31924665c86d47af6b1f22a74f594f2e1dc0ed2d)

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [Bug c++/107461] [12 Regression] ambiguity error for friend with templated constexpr argument
  2022-10-30  8:17 [Bug c++/107461] New: GCC rejects program with ambiguity error jlame646 at gmail dot com
                   ` (15 preceding siblings ...)
  2023-02-06 16:33 ` [Bug c++/107461] [12 " cvs-commit at gcc dot gnu.org
@ 2023-02-06 16:36 ` ppalka at gcc dot gnu.org
  2023-03-03 14:12 ` ppalka at gcc dot gnu.org
  17 siblings, 0 replies; 19+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-02-06 16:36 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #15 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed, hopefully

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [Bug c++/107461] [12 Regression] ambiguity error for friend with templated constexpr argument
  2022-10-30  8:17 [Bug c++/107461] New: GCC rejects program with ambiguity error jlame646 at gmail dot com
                   ` (16 preceding siblings ...)
  2023-02-06 16:36 ` ppalka at gcc dot gnu.org
@ 2023-03-03 14:12 ` ppalka at gcc dot gnu.org
  17 siblings, 0 replies; 19+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-03-03 14:12 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |headch at gmail dot com

--- Comment #16 from Patrick Palka <ppalka at gcc dot gnu.org> ---
*** Bug 109001 has been marked as a duplicate of this bug. ***

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2023-03-03 14:12 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-30  8:17 [Bug c++/107461] New: GCC rejects program with ambiguity error jlame646 at gmail dot com
2022-10-30 19:13 ` [Bug c++/107461] " pinskia at gcc dot gnu.org
2022-11-08 14:19 ` [Bug c++/107461] [12/13 Regression] ambiguity error for friend with templated constexpr argument ppalka at gcc dot gnu.org
2023-01-13 11:37 ` rguenth at gcc dot gnu.org
2023-02-03 14:41 ` cvs-commit at gcc dot gnu.org
2023-02-03 15:07 ` [Bug c++/107461] [12 " cvs-commit at gcc dot gnu.org
2023-02-03 15:08 ` ppalka at gcc dot gnu.org
2023-02-04  7:26 ` raj.khem at gmail dot com
2023-02-04 10:37 ` jakub at gcc dot gnu.org
2023-02-04 10:39 ` jakub at gcc dot gnu.org
2023-02-04 10:39 ` [Bug c++/107461] [12/13 " jakub at gcc dot gnu.org
2023-02-04 17:02 ` ppalka at gcc dot gnu.org
2023-02-04 17:04 ` ppalka at gcc dot gnu.org
2023-02-04 17:14 ` jakub at gcc dot gnu.org
2023-02-06  2:35 ` cvs-commit at gcc dot gnu.org
2023-02-06  3:01 ` ppalka at gcc dot gnu.org
2023-02-06 16:33 ` [Bug c++/107461] [12 " cvs-commit at gcc dot gnu.org
2023-02-06 16:36 ` ppalka at gcc dot gnu.org
2023-03-03 14:12 ` ppalka at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).