public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/97407] New: Expanding alias template in concept satisfaction error is undesirable
@ 2020-10-13 19:04 redi at gcc dot gnu.org
  2020-10-13 19:10 ` [Bug c++/97407] " redi at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2020-10-13 19:04 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 97407
           Summary: Expanding alias template in concept satisfaction error
                    is undesirable
           Product: gcc
           Version: 10.2.1
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

Compiling this with -std=c++20:

#include <ranges>

template<typename T> concept False = false;

template<typename R>
requires False<std::ranges::iterator_t<R>>
void f(R&)
{ }

int main()
{
  int a[2];
  f(a);
}

Produces the expected error:

alias.C: In function ‘int main()’:
alias.C:13:6: error: use of function ‘void f(R&) [with R = int [2]]’ with
unsatisfied constraints
alias.C:7:6: note: declared here
alias.C:7:6: note: constraints not satisfied
alias.C: In instantiation of ‘void f(R&) [with R = int [2]]’:
alias.C:13:6:   required from here
alias.C:3:30:   required for the satisfaction of ‘False<decltype
(std::__detail::__ranges_begin(declval<_Container&>()))>’ [with _Container =
int[2]]
alias.C:3:38: note: the expression ‘false’ evaluated to ‘false’

However the second to last line refers to

std::__detail::__ranges_begin(declval<_Container&>()))

This is meaningless to users, and "_Container" is not used in the definitions
of ranges::iterator_t or anything it uses. The compiler seems drunk and is
remembering the template argument of a different, unrelated use of the same
alias template. That's probably PR 95310.

I think it would be better to leave that alias unexpanded, as
std::ranges::iterator_t<R>.

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

* [Bug c++/97407] Expanding alias template in concept satisfaction error is undesirable
  2020-10-13 19:04 [Bug c++/97407] New: Expanding alias template in concept satisfaction error is undesirable redi at gcc dot gnu.org
@ 2020-10-13 19:10 ` redi at gcc dot gnu.org
  2020-10-13 19:16 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2020-10-13 19:10 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Reduced:

template<typename T> T&& declval;

template<typename R> decltype(declval<R&>().begin()) begin_impl(R&);

template<typename R>
using iter_type_impl = decltype(begin_impl(declval<R&>()));

template<typename Wat>
struct unrelated
{
  using erm = iter_type_impl<Wat>;
};

template<typename R>
using iterator_t = iter_type_impl<R>;

template<typename T> concept False = false;

template<typename R>
requires False<iterator_t<R>>
void f(R&)
{ }

int main()
{
  int a[2];
  f(a);
}


alias.C: In function ‘int main()’:
alias.C:27:6: error: use of function ‘void f(R&) [with R = int [2]]’ with
unsatisfied constraints
   27 |   f(a);
      |      ^
alias.C:21:6: note: declared here
   21 | void f(R&)
      |      ^
alias.C:21:6: note: constraints not satisfied
alias.C: In instantiation of ‘void f(R&) [with R = int [2]]’:
alias.C:27:6:   required from here
alias.C:17:30:   required for the satisfaction of ‘False<decltype
(begin_impl(declval<Wat&>()))>’ [with Wat = int[2]]
alias.C:17:38: note: the expression ‘false’ evaluated to ‘false’
   17 | template<typename T> concept False = false;
      |                                      ^~~~~


Here we print decltype (begin_impl(declval<Wat&>())) which would be better left
as iterator_t<R>, especially because "Wat" comes from a completely unrelated
class template which isn't even instantiated, but happens to use the same alias
template as iterator_t uses.

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

* [Bug c++/97407] Expanding alias template in concept satisfaction error is undesirable
  2020-10-13 19:04 [Bug c++/97407] New: Expanding alias template in concept satisfaction error is undesirable redi at gcc dot gnu.org
  2020-10-13 19:10 ` [Bug c++/97407] " redi at gcc dot gnu.org
@ 2020-10-13 19:16 ` redi at gcc dot gnu.org
  2020-10-13 20:00 ` ppalka at gcc dot gnu.org
  2021-06-10 11:45 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2020-10-13 19:16 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2020-10-13

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This was reduced from https://wandbox.org/permlink/MGJIbRbNtWQeNDWq which was
posted at
https://www.reddit.com/r/cpp/comments/j9ndx1/increased_complexity_of_c20_range_algorithms/g8ktca8

#include <algorithm>
#include <iostream>
#include <iterator>
#include <ranges>
#include <vector>

struct Package {
    double weight;
    double price;

    void foo() {}
};

int main(){
    std::vector<Package> packages { 
        {100.0, 10.0}, 
        {104.0, 7.5},
        {95.0, 17.5},
        {91.0, 15.0},
        {100.1, 12.5 },
    };
    std::ranges::sort(packages, {}, &Package::foo);
}

The errors for this include the unwanted expansion of iterator_t using the
unrelated "_Container" name, but in this case the name _Container is never even
explained!

/opt/wandbox/gcc-head/include/c++/11.0.0/bits/iterator_concepts.h: In
substitution of 'template<class _Range, class _Comp, class _Proj>  requires
(random_access_range<_Range>) &&
(sortable<decltype(std::__detail::__ranges_begin((declval<_Container&>)())),
_Comp, _Proj>) constexpr std::ranges::borrowed_iterator_t<_Range>
std::ranges::__sort_fn::operator()(_Range&&, _Comp, _Proj) const [with _Range =
std::vector<Package>&; _Comp = std::ranges::less; _Proj = void
(Package::*)()]':
prog.cc:22:50:   required from here

The name _Container does not appear in the [with ...] list of template
arguments.

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

* [Bug c++/97407] Expanding alias template in concept satisfaction error is undesirable
  2020-10-13 19:04 [Bug c++/97407] New: Expanding alias template in concept satisfaction error is undesirable redi at gcc dot gnu.org
  2020-10-13 19:10 ` [Bug c++/97407] " redi at gcc dot gnu.org
  2020-10-13 19:16 ` redi at gcc dot gnu.org
@ 2020-10-13 20:00 ` ppalka at gcc dot gnu.org
  2021-06-10 11:45 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: ppalka at gcc dot gnu.org @ 2020-10-13 20:00 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #3 from Patrick Palka <ppalka at gcc dot gnu.org> ---
> I think it would be better to leave that alias unexpanded, as std::ranges::iterator_t<R>.

Agreed.  It seems we need to teach the pretty printer to avoid expanding types
for which alias_template_specialization_p is true.. looking into it.

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

* [Bug c++/97407] Expanding alias template in concept satisfaction error is undesirable
  2020-10-13 19:04 [Bug c++/97407] New: Expanding alias template in concept satisfaction error is undesirable redi at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2020-10-13 20:00 ` ppalka at gcc dot gnu.org
@ 2021-06-10 11:45 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2021-06-10 11:45 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
See also PR 89370 comment 2

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

end of thread, other threads:[~2021-06-10 11:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-13 19:04 [Bug c++/97407] New: Expanding alias template in concept satisfaction error is undesirable redi at gcc dot gnu.org
2020-10-13 19:10 ` [Bug c++/97407] " redi at gcc dot gnu.org
2020-10-13 19:16 ` redi at gcc dot gnu.org
2020-10-13 20:00 ` ppalka at gcc dot gnu.org
2021-06-10 11:45 ` redi 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).