Quantcast
Channel: Intel® Software - Intel® C++ Compiler
Viewing all articles
Browse latest Browse all 1175

Intel 19 type-deduction allows non-const lvalue reference to prvalue

$
0
0

Intel 19 (Update 5) for Windows introduces a regression in which it is possible to take a non-const l-value reference to a temporary (prvalue). This code is correctly flagged in VS2019 as aberrant.

#include <cstdio>

struct T
   {
   T(char ch) : m_ch( ch ) { printf("Constructing '%c' (0x%08p)\n", ch, this); }
  ~T() { printf("Destructing '%c' (0x%08p)\n", m_ch, this); }
   char m_ch;
   };

T CreateT(char ch)
   {
   return T{ch};
   }

template <typename T_>
void Func1(T_&& t)
   {
   printf("Calling Func1 on object '%c' (0x%08p)\n", t.m_ch, &t);
   }

void Func2(T& t)
   {
   printf("Calling Func2 on object '%c' (0x%08p)\n", t.m_ch, &t);
   }

int main()
{
    const auto& a = CreateT('A'); // ok, const l-value reference to r-value
    auto&& b = CreateT('B'); // ok, deduces to r-value (T&&)
    Func1(CreateT('C')); // ok, deduces to T&&
//  Func2(CreateT('D')); // error, cannot bind non-const l-value ref to r-value (Intel 19.0.5 allows this!)
//  auto& d = CreateT('D'); // error, cannot bind non-const l-value ref to r-value (Intel 19.0.5 allows this!)

    return 0;
}

 

TCE Open Date: 

Monday, November 18, 2019 - 17:13

Viewing all articles
Browse latest Browse all 1175

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>