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

            Bug ID: 84231
           Summary: [8 Regression] cannot bind non-const lvalue reference
                    of type ‘const char*&’ to an rvalue of type ‘const
                    char*’
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

From https://bugzilla.redhat.com/show_bug.cgi?id=1542187

GCC 8 rejects this valid code, but only inside a template (either in a function
template, or a member function of a class template):

struct format {
  template<typename T> format& operator%(const T&) { return *this; }
  template<typename T> format& operator%(T&) { return *this; }
};

format f;

template <typename>
void function_template(bool b)
{
  // Compiles OK with array lvalue:
  f % (b ? "x" : "x");

  // Fails with pointer rvalue:
  f % (b ? "" : "x");
}

void normal_function(bool b)
{
  // Both cases compile OK in non-template function:
  f % (b ? "x" : "x");
  f % (b ? "" : "x");

  function_template<void>(b);
}

Reply via email to