Bug 96560 - Substitution triggers compile-time error when it shouldn't
Summary: Substitution triggers compile-time error when it shouldn't
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: unknown
: P3 normal
Target Milestone: 12.0
Assignee: Patrick Palka
Keywords: patch, rejects-valid
Depends on:
Blocks: c++-core-issues
  Show dependency treegraph
Reported: 2020-08-10 17:52 UTC by Marek Polacek
Modified: 2021-06-11 20:11 UTC (History)
2 users (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2021-04-28 00:00:00


Note You need to log in before you can comment on or make changes to this bug.
Description Marek Polacek 2020-08-10 17:52:35 UTC
This triggers the static_assert while it shouldn't, because DR 1227 says "The substitution proceeds in lexical order and stops when a condition that causes deduction to fail is encountered."  Compiles with clang++/EDG.

template<bool, typename = void>
struct enable_if { };

template<typename T>
struct enable_if<true, T> {
  using type = T;

template<class T>
struct hard_error {
  static_assert(sizeof(T) == 0);
  static inline constexpr bool value = true;

template<class T>
struct always_false {
  static inline constexpr bool value = false;

template<class T>
int foo (int, typename enable_if<always_false<T>::value, int>::type = 0,
              typename enable_if<hard_error<T>::value, int>::type = 0 )
  return 0;

template<class T>
char const *foo (long)
  return "";

main ()
  char const *sz = foo<int>(0);
Comment 2 CVS Commits 2021-06-11 20:09:55 UTC
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:


commit r12-1398-gb0d73a66ae3962fa83309527d85613d72a6aa43d
Author: Patrick Palka <ppalka@redhat.com>
Date:   Fri Jun 11 16:00:52 2021 -0400

    c++: Substitute into function parms in lexical order [PR96560]
    This makes tsubst_arg_types substitute into a function's parameter types
    in left-to-right instead of right-to-left order, in accordance with DR 1227.
            DR 1227
            PR c++/96560
            * pt.c (tsubst_arg_types): Rearrange so that we substitute into
            TYPE_ARG_TYPES in forward order while short circuiting
            appropriately.  Adjust formatting.
            * g++.dg/template/sfinae-dr1227.C: New test.
Comment 3 Patrick Palka 2021-06-11 20:11:23 UTC