public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/110580] New: [14 Regression] gcc fails to typecheck nix-2.16.1 source: error: invalid initialization of reference of type
@ 2023-07-06 21:46 slyfox at gcc dot gnu.org
  2023-07-07  6:53 ` [Bug c++/110580] " rguenth at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: slyfox at gcc dot gnu.org @ 2023-07-06 21:46 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110580
           Summary: [14 Regression] gcc fails to typecheck nix-2.16.1
                    source: error: invalid initialization of reference of
                    type
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: slyfox at gcc dot gnu.org
  Target Milestone: ---

Created attachment 55495
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55495&action=edit
nar-accessor.cc.cc.xz

Originally observed the build failure on nix-2.16.1 source when building with
gcc r14-2344-g9f4f833455bb35.

I suspect it might be a form of https://gcc.gnu.org/PR110523 regression. But
filing just in case.

Attached unmodified preprocessed example.

The build succeeds on gcc-13:

$ g++-13 -c nar-accessor.cc.cc -std=c++2a
# ok

$ g++-14 -c nar-accessor.cc.cc -std=c++2a
nar-accessor.cc.cc: In instantiation of 'std::pair<typename std::_Rb_tree<_Key,
std::pair<const _Key, _Val>, std::_Select1st<std::pair<const _Key, _Val> >,
_Compare, typename
__gnu_cxx::__alloc_traits<_Allocator>::rebind<std::pair<const _Key, _Val>
>::other>::iterator, bool> std::map<_Key, _Tp, _Compare,
_Alloc>::emplace(_Args&& ...) [with _Args = {std::basic_string_view<char,
std::char_traits<char> >, nix::NarMember}; _Key =
std::__cxx11::basic_string<char>; _Tp = nix::NarMember; _Compare =
std::less<std::__cxx11::basic_string<char> >; _Alloc =
std::allocator<std::pair<const std::__cxx11::basic_string<char>,
nix::NarMember> >; typename std::_Rb_tree<_Key, std::pair<const _Key, _Val>,
std::_Select1st<std::pair<const _Key, _Val> >, _Compare, typename
__gnu_cxx::__alloc_traits<_Allocator>::rebind<std::pair<const _Key, _Val>
>::other>::iterator = std::_Rb_tree_iterator<std::pair<const
std::__cxx11::basic_string<char>, nix::NarMember> >; typename
__gnu_cxx::__alloc_traits<_Allocator>::rebind<std::pair<const _Key, _Val>
>::other = std::allocator<std::pair<const std::__cxx11::basic_string<char>,
nix::NarMember> >; typename
__gnu_cxx::__alloc_traits<_Allocator>::rebind<std::pair<const _Key, _Val> > =
__gnu_cxx::__alloc_traits<std::allocator<std::pair<const
std::__cxx11::basic_string<char>, nix::NarMember> >, std::pair<const
std::__cxx11::basic_string<char>, nix::NarMember> >::rebind<std::pair<const
std::__cxx11::basic_string<char>, nix::NarMember> >; typename
_Allocator::value_type = std::pair<const std::__cxx11::basic_string<char>,
nix::NarMember>]':
nar-accessor.cc.cc:126951:62:   required from here
nar-accessor.cc.cc:33745:23: error: invalid initialization of reference of type
'const std::map<std::__cxx11::basic_string<char>, nix::NarMember>::key_type&'
{aka 'const std::__cxx11::basic_string<char>&'} from expression of type
'std::basic_string_view<char>'
33745 |       const key_type& __k = __a;
      |                       ^~~

$ g++ -v |& unnix
Using built-in specs.
COLLECT_GCC=/<<NIX>>/gcc-14.0.0/bin/g++
COLLECT_LTO_WRAPPER=/<<NIX>>/gcc-14.0.0/libexec/gcc/x86_64-unknown-linux-gnu/14.0.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with:
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.0 99999999 (experimental) (GCC)

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

* [Bug c++/110580] [14 Regression] gcc fails to typecheck nix-2.16.1 source: error: invalid initialization of reference of type
  2023-07-06 21:46 [Bug c++/110580] New: [14 Regression] gcc fails to typecheck nix-2.16.1 source: error: invalid initialization of reference of type slyfox at gcc dot gnu.org
@ 2023-07-07  6:53 ` rguenth at gcc dot gnu.org
  2023-07-09  7:02 ` pinskia at gcc dot gnu.org
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-07  6:53 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |needs-bisection,
                   |                            |rejects-valid
   Target Milestone|---                         |14.0

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

* [Bug c++/110580] [14 Regression] gcc fails to typecheck nix-2.16.1 source: error: invalid initialization of reference of type
  2023-07-06 21:46 [Bug c++/110580] New: [14 Regression] gcc fails to typecheck nix-2.16.1 source: error: invalid initialization of reference of type slyfox at gcc dot gnu.org
  2023-07-07  6:53 ` [Bug c++/110580] " rguenth at gcc dot gnu.org
@ 2023-07-09  7:02 ` pinskia at gcc dot gnu.org
  2023-07-09 15:56 ` pinskia at gcc dot gnu.org
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-09  7:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Reducing ...

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

* [Bug c++/110580] [14 Regression] gcc fails to typecheck nix-2.16.1 source: error: invalid initialization of reference of type
  2023-07-06 21:46 [Bug c++/110580] New: [14 Regression] gcc fails to typecheck nix-2.16.1 source: error: invalid initialization of reference of type slyfox at gcc dot gnu.org
  2023-07-07  6:53 ` [Bug c++/110580] " rguenth at gcc dot gnu.org
  2023-07-09  7:02 ` pinskia at gcc dot gnu.org
@ 2023-07-09 15:56 ` pinskia at gcc dot gnu.org
  2023-07-09 18:26 ` pinskia at gcc dot gnu.org
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-09 15:56 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2023-07-09
             Status|UNCONFIRMED                 |NEW

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Reduced un-preprocessed source:
```
#include <map>
#include <stack>
#include <string>

struct NarMember {
  std::map<std::string, NarMember> children;
};
std::stack<NarMember *> parents;
std::string_view g();
void createMember(NarMember member) {
  parents.top()->children.emplace(g(),
                                  std::move(member));
}
```

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

* [Bug c++/110580] [14 Regression] gcc fails to typecheck nix-2.16.1 source: error: invalid initialization of reference of type
  2023-07-06 21:46 [Bug c++/110580] New: [14 Regression] gcc fails to typecheck nix-2.16.1 source: error: invalid initialization of reference of type slyfox at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2023-07-09 15:56 ` pinskia at gcc dot gnu.org
@ 2023-07-09 18:26 ` pinskia at gcc dot gnu.org
  2023-07-09 18:37 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-09 18:26 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Reduced all the way:
```
template <typename _Tp> struct remove_reference {
  using type = __remove_reference(_Tp);
};
template <typename _Tp>
using remove_reference_t = typename remove_reference<_Tp>::type;
template <typename _Tp, typename _Up>
inline constexpr bool is_same_v = __is_same(_Tp, _Up);

template <typename _Key> class s3 {
public:
  template <typename _Up, typename _Vp = remove_reference_t<_Up>>
  static constexpr bool __usable_key = is_same_v<const _Vp, const _Key>;
  template <typename _Args> void f(_Args __args, int t) {
    if constexpr (__usable_key<_Args>) {
      const _Key &__k = __args;
    }
  }
};
struct s0 {};
struct s1 {};
s1 g();
void createMember(int member, s3<s0> &children) { children.f(g(), member); }

```

Or if using the internal type_traits is bad idea here is better testcase:
```

#include <type_traits>

using namespace std;

template <typename _Key> class s3 {
public:
  template <typename _Up, typename _Vp = remove_reference_t<_Up>>
  static constexpr bool __usable_key = is_same_v<const _Vp, const _Key>;
  template <typename _Args> void f(_Args __args, int t) {
    if constexpr (__usable_key<_Args>) {
      const _Key &__k = __args;
    }
  }
};
struct s0 {};
struct s1 {};
s1 g();
void createMember(int member, s3<s0> &children) { children.f(g(), member); }
```

Here is a testcase using static assert rather than if constexpr:
```
#include <type_traits>

using namespace std;

template <typename _Key> class s3 {
public:
  template <typename _Up, typename _Vp = remove_reference_t<_Up>>
  static constexpr bool __usable_key = is_same_v<const _Vp, const _Key>;
  template <typename _Args> void f(_Args __args, int t) {
    static_assert(!__usable_key<_Args>);
  }
};
struct s0 {};
struct s1 {};
s1 g();
void createMember(int member, s3<s0> &children) { children.f(g(), member); }
```

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

* [Bug c++/110580] [14 Regression] gcc fails to typecheck nix-2.16.1 source: error: invalid initialization of reference of type
  2023-07-06 21:46 [Bug c++/110580] New: [14 Regression] gcc fails to typecheck nix-2.16.1 source: error: invalid initialization of reference of type slyfox at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2023-07-09 18:26 ` pinskia at gcc dot gnu.org
@ 2023-07-09 18:37 ` pinskia at gcc dot gnu.org
  2023-07-10  5:47 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-09 18:37 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Slightly more reduced:
```
#include <type_traits>

using std::is_same_v;

struct s0 {};
struct s1 {};
template <typename _Key> 
struct s3 {
  template <typename _Up, typename _Vp = _Up>
  static constexpr bool __usable_key = is_same_v<_Vp, _Key>;
  static_assert(!__usable_key<s1>);
};
s3<s0> t;

```
If I remove _Vp or remove it from being type dependent, it works.

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

* [Bug c++/110580] [14 Regression] gcc fails to typecheck nix-2.16.1 source: error: invalid initialization of reference of type
  2023-07-06 21:46 [Bug c++/110580] New: [14 Regression] gcc fails to typecheck nix-2.16.1 source: error: invalid initialization of reference of type slyfox at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2023-07-09 18:37 ` pinskia at gcc dot gnu.org
@ 2023-07-10  5:47 ` pinskia at gcc dot gnu.org
  2023-07-10  5:53 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-10  5:47 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Here is another testcase:
```
struct s0 {};
struct s1 {};
template <typename T>
struct t
{
        static constexpr bool v = false;
};
template<>
struct t<s0>
{
        static constexpr bool v = true;
};
template <typename _Key> 
struct s3 {
  template <typename _Up, typename _Vp = _Up>
  static constexpr bool __usable_key = t<_Vp>::v;
  static_assert(__usable_key<s0>);
  static_assert(!__usable_key<s1>);
};
s3<s0> t2;
```

I get the feeling _Up in the default template argument of __usable_key  is
being replaced with _Key template argument for some reason.

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

* [Bug c++/110580] [14 Regression] gcc fails to typecheck nix-2.16.1 source: error: invalid initialization of reference of type
  2023-07-06 21:46 [Bug c++/110580] New: [14 Regression] gcc fails to typecheck nix-2.16.1 source: error: invalid initialization of reference of type slyfox at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2023-07-10  5:47 ` pinskia at gcc dot gnu.org
@ 2023-07-10  5:53 ` pinskia at gcc dot gnu.org
  2023-07-10 18:24 ` ppalka at gcc dot gnu.org
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-10  5:53 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |accepts-invalid

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
yes my theory is correct and becomes obvious with the error message for:
```

struct s0 {};
struct s1 {};
struct s2 {};
template <typename T>
struct t;
template <typename _Key> 
struct s3 {
  template <typename _Up, typename _Vp = _Up>
  static constexpr bool __usable_key = t<_Vp>::v;
  static_assert(__usable_key<s0>);
  static_assert(__usable_key<s1>);
};
s3<s2> t2;
```
Error message:
```
<source>: In instantiation of 'constexpr const bool s3<s2>::__usable_key<s0,
s2>':
...
<source>: In instantiation of 'constexpr const bool s3<s2>::__usable_key<s1,
s2>':
```
s2 there is definitely incorrect

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

* [Bug c++/110580] [14 Regression] gcc fails to typecheck nix-2.16.1 source: error: invalid initialization of reference of type
  2023-07-06 21:46 [Bug c++/110580] New: [14 Regression] gcc fails to typecheck nix-2.16.1 source: error: invalid initialization of reference of type slyfox at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2023-07-10  5:53 ` pinskia at gcc dot gnu.org
@ 2023-07-10 18:24 ` ppalka at gcc dot gnu.org
  2023-07-11 14:06 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-07-10 18:24 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ppalka at gcc dot gnu.org
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |ppalka at gcc dot gnu.org
           Keywords|needs-bisection             |

--- Comment #7 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Started with r14-2170-g4cf64d9cc2faf4.

(In reply to Andrew Pinski from comment #5)
> I get the feeling _Up in the default template argument of __usable_key  is
> being replaced with _Key template argument for some reason.

Interesting bug.. Thanks for the nice reduction.

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

* [Bug c++/110580] [14 Regression] gcc fails to typecheck nix-2.16.1 source: error: invalid initialization of reference of type
  2023-07-06 21:46 [Bug c++/110580] New: [14 Regression] gcc fails to typecheck nix-2.16.1 source: error: invalid initialization of reference of type slyfox at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  2023-07-10 18:24 ` ppalka at gcc dot gnu.org
@ 2023-07-11 14:06 ` cvs-commit at gcc dot gnu.org
  2023-07-11 14:06 ` ppalka at gcc dot gnu.org
  2023-07-11 19:02 ` slyfox at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-07-11 14:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 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:b76d71564925abcabe6f5ad61d904b23c682cdfb

commit r14-2433-gb76d71564925abcabe6f5ad61d904b23c682cdfb
Author: Patrick Palka <ppalka@redhat.com>
Date:   Tue Jul 11 10:05:19 2023 -0400

    c++: coercing variable template from current inst [PR110580]

    Here during ahead of time coercion of the variable template-id v1<int>,
    since we pass only the innermost arguments to coerce_template_parms (and
    outer arguments are still dependent at this point), substitution of the
    default template argument V=U just lowers U from level 2 to level 1 rather
    than replacing it with int as expected.  Thus after coercion we incorrectly
    end up with (effectively) v1<int, T> instead of v1<int, int>.

    Coercion of a class/alias template-id on the other hand always passes
    all levels arguments, which avoids this issue.  So this patch makes us
    do the same for variable template-ids.

            PR c++/110580

    gcc/cp/ChangeLog:

            * pt.cc (lookup_template_variable): Pass all levels of arguments
            to coerce_template_parms, and use the parameters from the most
            general template.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp1y/var-templ83.C: New test.

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

* [Bug c++/110580] [14 Regression] gcc fails to typecheck nix-2.16.1 source: error: invalid initialization of reference of type
  2023-07-06 21:46 [Bug c++/110580] New: [14 Regression] gcc fails to typecheck nix-2.16.1 source: error: invalid initialization of reference of type slyfox at gcc dot gnu.org
                   ` (8 preceding siblings ...)
  2023-07-11 14:06 ` cvs-commit at gcc dot gnu.org
@ 2023-07-11 14:06 ` ppalka at gcc dot gnu.org
  2023-07-11 19:02 ` slyfox at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-07-11 14:06 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

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

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

* [Bug c++/110580] [14 Regression] gcc fails to typecheck nix-2.16.1 source: error: invalid initialization of reference of type
  2023-07-06 21:46 [Bug c++/110580] New: [14 Regression] gcc fails to typecheck nix-2.16.1 source: error: invalid initialization of reference of type slyfox at gcc dot gnu.org
                   ` (9 preceding siblings ...)
  2023-07-11 14:06 ` ppalka at gcc dot gnu.org
@ 2023-07-11 19:02 ` slyfox at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: slyfox at gcc dot gnu.org @ 2023-07-11 19:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from Sergei Trofimovich <slyfox at gcc dot gnu.org> ---
I confirm the change fixed nix-2.16.1 and json-3.11.2 builds for me. Thank you!

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

end of thread, other threads:[~2023-07-11 19:02 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-06 21:46 [Bug c++/110580] New: [14 Regression] gcc fails to typecheck nix-2.16.1 source: error: invalid initialization of reference of type slyfox at gcc dot gnu.org
2023-07-07  6:53 ` [Bug c++/110580] " rguenth at gcc dot gnu.org
2023-07-09  7:02 ` pinskia at gcc dot gnu.org
2023-07-09 15:56 ` pinskia at gcc dot gnu.org
2023-07-09 18:26 ` pinskia at gcc dot gnu.org
2023-07-09 18:37 ` pinskia at gcc dot gnu.org
2023-07-10  5:47 ` pinskia at gcc dot gnu.org
2023-07-10  5:53 ` pinskia at gcc dot gnu.org
2023-07-10 18:24 ` ppalka at gcc dot gnu.org
2023-07-11 14:06 ` cvs-commit at gcc dot gnu.org
2023-07-11 14:06 ` ppalka at gcc dot gnu.org
2023-07-11 19:02 ` slyfox 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).