[llvm-bugs] [Bug 47233] New: clang rejects valid c++ code

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Aug 19 05:58:29 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=47233

            Bug ID: 47233
           Summary: clang rejects valid c++ code
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: tangyixuan at mail.dlut.edu.cn
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Please consider the following code, g++ compiles it successfully, while clang++
reports two errors:

$ cat s.C
#include <valarray>
#include <iostream>
using namespace std;

template<class Value>
class T
{
  const long &dim;
public:
  T(const double &_dim) : dim(_dim)
  {}
};
int main(int argc, char *argv[])
{
  long dim = 10;
  T< valarray<double> > factory(dim);
}

$ clang++ -c s.C
s.C:10:31: error: reference member 'dim' binds to a temporary object whose
lifetime would be shorter than the lifetime of the constructed object
  T(const double &_dim) : dim(_dim)
                              ^~~~
s.C:8:15: note: reference member declared here
  const long &dim;
              ^
s.C:10:31: error: reference member 'dim' binds to a temporary object whose
lifetime would be shorter than the lifetime of the constructed object
  T(const double &_dim) : dim(_dim)
                              ^~~~
s.C:16:25: note: in instantiation of member function 'T<std::valarray<double>
>::T' requested here
  T< valarray<double> > factory(dim);
                        ^
s.C:8:15: note: reference member declared here
  const long &dim;
              ^
2 errors generated.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200819/8f6d00c0/attachment.html>


More information about the llvm-bugs mailing list