LoginSignup
0
0

More than 5 years have passed since last update.

C++ Templates The Complete Guide(2nd Edition) (3)basics/referror2.cpp

Posted at

目的

このコンパイル記録は、コンパイラおよび対応標準、コンパイラの版により、コンパイルエラーMessageの違いを記録し、どのエラーが出たら、どの版またはどの対応標準にすればエラーが少なくなるかを考察するための資料です。

成果

コンパイラの種類、対応標準の違いによってエラーの数が違う。同じエラーであってもMessageの表現が違う。Error Messageのネットで検索する際に役立つ。

背景

C++のTemplate使いこなせてない。
The Complete Guide(2nd Edition)
http://www.tmplbook.com/code/code.html
コンパイルしながら勉強。

勉強の記録

https://researchmap.jp/joqzln3gi-1797580/#_1797580
だと, qiitaのようにコード表示機能がないためわかりにくい。
C++ Templates The Complete Guide(2nd Edition)をclang++とg++でコンパイルしてみた
https://qiita.com/kaizen_nagoya/items/a7065ea839cb33793bdf
コンパイルエラーになったものを
clang++, g++の -std=c++03, -std=c++2a
でコンパイルしながら一つづつ確認。

clang++

clang version 6.0.0 (tags/RELEASE_600/final)
Target: x86_64-apple-darwin17.5.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm/bin

g++

g++ (Homebrew GCC 8.1.0) 8.1.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

basics/projectioniterator.cpp
#include <vector>
#include <iostream>

template<typename T, int& SZ>     // Note: size is reference
class Arr {
private:
  std::vector<T> elems;
public:
  Arr() : elems(SZ) {           // use current SZ as initial vector size
  }
  void print() const {
    for (int i=0; i<SZ; ++i) {  // loop over SZ elements
      std::cout << elems[i] << ' ';
    }
  }
};

int size = 10;

int main()
{
  Arr<int&,size> y; // compile-time ERROR deep in the code of class std::vector<>

  Arr<int,size> x;  // initializes internal vector with 10 elements
  x.print();        // OK
  size += 100;      // OOPS: modifies SZ in Arr<>
  x.print();        // run-time ERROR: invalid memory access: loops over 120 elements
}
cpla.sh
$ ../cpla.sh referror2
../cpla.sh: line 1: spla.sh: command not found
$ clang++ referror2.cpp -std=c++03 -Wall
In file included from referror2.cpp:1:
In file included from /usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:266:
In file included from /usr/local/Cellar/llvm/6.0.0/include/c++/v1/__bit_reference:15:
In file included from /usr/local/Cellar/llvm/6.0.0/include/c++/v1/algorithm:643:
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/memory:1770:16: error: 'pointer'
      declared as a pointer to a reference of type 'int &'
    typedef _Tp*              pointer;
               ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/memory:1515:22: note: in
      instantiation of template class 'std::__1::allocator<int &>' requested
      here
    typedef typename allocator_type::value_type value_type;
                     ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:325:22: note: in
      instantiation of template class
      'std::__1::allocator_traits<std::__1::allocator<int &> >' requested here
    typedef typename __alloc_traits::size_type       size_type;
                     ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:448:15: note: in
      instantiation of template class 'std::__1::__vector_base<int &,
      std::__1::allocator<int &> >' requested here
    : private __vector_base<_Tp, _Allocator>
              ^
referror2.cpp:7:20: note: in instantiation of template class
      'std::__1::vector<int &, std::__1::allocator<int &> >' requested here
    std::vector<T> elems;
                   ^
referror2.cpp:22:18: note: in instantiation of template class
      'Arr<int &, &size>' requested here
  Arr<int&,size> y; // compile-time ERROR deep in the code of class std:...
                 ^
In file included from referror2.cpp:1:
In file included from /usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:266:
In file included from /usr/local/Cellar/llvm/6.0.0/include/c++/v1/__bit_reference:15:
In file included from /usr/local/Cellar/llvm/6.0.0/include/c++/v1/algorithm:643:
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/memory:1771:22: error: 
      'const_pointer' declared as a pointer to a reference of type 'int &'
    typedef const _Tp*        const_pointer;
                     ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/memory:1785:45: error: multiple
      overloads of 'address' instantiate to the same signature
      'std::__1::allocator<int &>::const_pointer (std::__1::allocator<int
      &>::const_reference) const throw()' (aka 'int (int &) const throw()')
    _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x...
                                            ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/memory:1783:39: note: previous
      declaration is here
    _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT
                                      ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/memory:950:22: error: implicit
      instantiation of undefined template
      'std::__1::__pointer_traits_element_type<int, false>'
    typedef typename __pointer_traits_element_type<pointer>::type    ele...
                     ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/memory:1074:22: note: in
      instantiation of template class 'std::__1::pointer_traits<int>' requested
      here
    typedef typename pointer_traits<_Ptr>::template rebind<void>::other type;
                     ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/memory:1519:22: note: in
      instantiation of template class 'std::__1::__void_pointer<int,
      std::__1::allocator<int &>, false>' requested here
    typedef typename __void_pointer<pointer, allocator_type>::type void_pointer;
                     ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:325:22: note: in
      instantiation of template class
      'std::__1::allocator_traits<std::__1::allocator<int &> >' requested here
    typedef typename __alloc_traits::size_type       size_type;
                     ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:448:15: note: in
      instantiation of template class 'std::__1::__vector_base<int &,
      std::__1::allocator<int &> >' requested here
    : private __vector_base<_Tp, _Allocator>
              ^
referror2.cpp:7:20: note: in instantiation of template class
      'std::__1::vector<int &, std::__1::allocator<int &> >' requested here
    std::vector<T> elems;
                   ^
referror2.cpp:22:18: note: in instantiation of template class
      'Arr<int &, &size>' requested here
  Arr<int&,size> y; // compile-time ERROR deep in the code of class std:...
                 ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/memory:740:8: note: template is
      declared here
struct __pointer_traits_element_type;
       ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/memory:1074:53: error: 'rebind'
      following the 'template' keyword does not refer to a template
    typedef typename pointer_traits<_Ptr>::template rebind<void>::other type;
                                                    ^~~~~~
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/memory:1519:22: note: in
      instantiation of template class 'std::__1::__void_pointer<int,
      std::__1::allocator<int &>, false>' requested here
    typedef typename __void_pointer<pointer, allocator_type>::type void_pointer;
                     ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:325:22: note: in
      instantiation of template class
      'std::__1::allocator_traits<std::__1::allocator<int &> >' requested here
    typedef typename __alloc_traits::size_type       size_type;
                     ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:448:15: note: in
      instantiation of template class 'std::__1::__vector_base<int &,
      std::__1::allocator<int &> >' requested here
    : private __vector_base<_Tp, _Allocator>
              ^
referror2.cpp:7:20: note: in instantiation of template class
      'std::__1::vector<int &, std::__1::allocator<int &> >' requested here
    std::vector<T> elems;
                   ^
referror2.cpp:22:18: note: in instantiation of template class
      'Arr<int &, &size>' requested here
  Arr<int&,size> y; // compile-time ERROR deep in the code of class std:...
                 ^
In file included from referror2.cpp:1:
In file included from /usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:266:
In file included from /usr/local/Cellar/llvm/6.0.0/include/c++/v1/__bit_reference:15:
In file included from /usr/local/Cellar/llvm/6.0.0/include/c++/v1/algorithm:643:
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/memory:852:22: error: type 'int'
      cannot be used prior to '::' because it has no members
    typedef typename _Tp::template rebind<_Up>::other type;
                     ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/memory:957:27: note: in
      instantiation of template class 'std::__1::__pointer_traits_rebind<int,
      const void, false>' requested here
        {typedef typename __pointer_traits_rebind<pointer, _Up>::type other;};
                          ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/memory:1097:44: note: in
      instantiation of template class
      'std::__1::pointer_traits<int>::rebind<const void>' requested here
    typedef typename pointer_traits<_Ptr>::template rebind<const void>::...
                                           ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/memory:1520:22: note: in
      instantiation of template class 'std::__1::__const_void_pointer<int,
      std::__1::allocator<int &>, false>' requested here
    typedef typename __const_void_pointer<pointer, allocator_type>::typ...
                     ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:325:22: note: in
      instantiation of template class
      'std::__1::allocator_traits<std::__1::allocator<int &> >' requested here
    typedef typename __alloc_traits::size_type       size_type;
                     ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:448:15: note: in
      instantiation of template class 'std::__1::__vector_base<int &,
      std::__1::allocator<int &> >' requested here
    : private __vector_base<_Tp, _Allocator>
              ^
referror2.cpp:7:20: note: in instantiation of template class
      'std::__1::vector<int &, std::__1::allocator<int &> >' requested here
    std::vector<T> elems;
                   ^
referror2.cpp:22:18: note: in instantiation of template class
      'Arr<int &, &size>' requested here
  Arr<int&,size> y; // compile-time ERROR deep in the code of class std:...
                 ^
In file included from referror2.cpp:1:
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:457:30: error: 
      '__alloc_traits' is a protected member of 'std::__1::__vector_base<int &,
      std::__1::allocator<int &> >'
    typedef typename __base::__alloc_traits          __alloc_traits;
                             ^
referror2.cpp:7:20: note: in instantiation of template class
      'std::__1::vector<int &, std::__1::allocator<int &> >' requested here
    std::vector<T> elems;
                   ^
referror2.cpp:22:18: note: in instantiation of template class
      'Arr<int &, &size>' requested here
  Arr<int&,size> y; // compile-time ERROR deep in the code of class std:...
                 ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:322:54: note: declared
      protected here
    typedef allocator_traits<allocator_type>         __alloc_traits;
                                                     ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:458:30: error: 'reference' is
      a protected member of 'std::__1::__vector_base<int &,
      std::__1::allocator<int &> >'
    typedef typename __base::reference               reference;
                             ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:323:54: note: declared
      protected here
    typedef value_type&                              reference;
                                                     ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:459:30: error: 
      'const_reference' is a protected member of 'std::__1::__vector_base<int &,
      std::__1::allocator<int &> >'
    typedef typename __base::const_reference         const_reference;
                             ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:324:54: note: declared
      protected here
    typedef const value_type&                        const_reference;
                                                     ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:460:30: error: 'size_type' is
      a protected member of 'std::__1::__vector_base<int &,
      std::__1::allocator<int &> >'
    typedef typename __base::size_type               size_type;
                             ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:325:54: note: declared
      protected here
    typedef typename __alloc_traits::size_type       size_type;
                                                     ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:461:30: error: 
      'difference_type' is a protected member of 'std::__1::__vector_base<int &,
      std::__1::allocator<int &> >'
    typedef typename __base::difference_type         difference_type;
                             ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:326:54: note: declared
      protected here
    typedef typename __alloc_traits::difference_type difference_type;
                                                     ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:462:30: error: 'pointer' is a
      protected member of 'std::__1::__vector_base<int &,
      std::__1::allocator<int &> >'
    typedef typename __base::pointer                 pointer;
                             ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:327:54: note: declared
      protected here
    typedef typename __alloc_traits::pointer         pointer;
                                                     ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:463:30: error: 
      'const_pointer' is a protected member of 'std::__1::__vector_base<int &,
      std::__1::allocator<int &> >'
    typedef typename __base::const_pointer           const_pointer;
                             ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:328:54: note: declared
      protected here
    typedef typename __alloc_traits::const_pointer   const_pointer;
                                                     ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:671:15: error: 'data'
      declared as a pointer to a reference of type 'std::__1::vector<int &,
      std::__1::allocator<int &> >::value_type' (aka 'int &')
    value_type*       data() _NOEXCEPT
              ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:674:21: error: 'data'
      declared as a pointer to a reference of type 'std::__1::vector<int &,
      std::__1::allocator<int &> >::value_type' (aka 'int &')
    const value_type* data() const _NOEXCEPT
                    ^
15 errors generated.
$ clang++ referror2.cpp -std=c++2a -Wall
In file included from referror2.cpp:1:
In file included from /usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:266:
In file included from /usr/local/Cellar/llvm/6.0.0/include/c++/v1/__bit_reference:15:
In file included from /usr/local/Cellar/llvm/6.0.0/include/c++/v1/algorithm:643:
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/memory:1770:16: error: 'pointer'
      declared as a pointer to a reference of type 'int &'
    typedef _Tp*              pointer;
               ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/memory:1515:22: note: in
      instantiation of template class 'std::__1::allocator<int &>' requested
      here
    typedef typename allocator_type::value_type value_type;
                     ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:325:22: note: in
      instantiation of template class
      'std::__1::allocator_traits<std::__1::allocator<int &> >' requested here
    typedef typename __alloc_traits::size_type       size_type;
                     ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:448:15: note: in
      instantiation of template class 'std::__1::__vector_base<int &,
      std::__1::allocator<int &> >' requested here
    : private __vector_base<_Tp, _Allocator>
              ^
referror2.cpp:7:20: note: in instantiation of template class
      'std::__1::vector<int &, std::__1::allocator<int &> >' requested here
    std::vector<T> elems;
                   ^
referror2.cpp:22:18: note: in instantiation of template class
      'Arr<int &, &size>' requested here
  Arr<int&,size> y; // compile-time ERROR deep in the code of class std:...
                 ^
In file included from referror2.cpp:1:
In file included from /usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:266:
In file included from /usr/local/Cellar/llvm/6.0.0/include/c++/v1/__bit_reference:15:
In file included from /usr/local/Cellar/llvm/6.0.0/include/c++/v1/algorithm:643:
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/memory:1771:22: error: 
      'const_pointer' declared as a pointer to a reference of type 'int &'
    typedef const _Tp*        const_pointer;
                     ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/memory:1785:45: error: multiple
      overloads of 'address' instantiate to the same signature
      'std::__1::allocator<int &>::const_pointer (std::__1::allocator<int
      &>::const_reference) const noexcept' (aka 'int (int &) const noexcept')
    _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x...
                                            ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/memory:1783:39: note: previous
      declaration is here
    _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT
                                      ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/memory:950:22: error: implicit
      instantiation of undefined template
      'std::__1::__pointer_traits_element_type<int, false>'
    typedef typename __pointer_traits_element_type<pointer>::type    ele...
                     ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/memory:1072:22: note: in
      instantiation of template class 'std::__1::pointer_traits<int>' requested
      here
    typedef typename pointer_traits<_Ptr>::template rebind<void> type;
                     ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/memory:1519:22: note: in
      instantiation of template class 'std::__1::__void_pointer<int,
      std::__1::allocator<int &>, false>' requested here
    typedef typename __void_pointer<pointer, allocator_type>::type void_pointer;
                     ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:325:22: note: in
      instantiation of template class
      'std::__1::allocator_traits<std::__1::allocator<int &> >' requested here
    typedef typename __alloc_traits::size_type       size_type;
                     ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:448:15: note: in
      instantiation of template class 'std::__1::__vector_base<int &,
      std::__1::allocator<int &> >' requested here
    : private __vector_base<_Tp, _Allocator>
              ^
referror2.cpp:7:20: note: in instantiation of template class
      'std::__1::vector<int &, std::__1::allocator<int &> >' requested here
    std::vector<T> elems;
                   ^
referror2.cpp:22:18: note: in instantiation of template class
      'Arr<int &, &size>' requested here
  Arr<int&,size> y; // compile-time ERROR deep in the code of class std:...
                 ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/memory:740:8: note: template is
      declared here
struct __pointer_traits_element_type;
       ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/memory:1072:53: error: 'rebind'
      following the 'template' keyword does not refer to a template
    typedef typename pointer_traits<_Ptr>::template rebind<void> type;
                                                    ^~~~~~
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/memory:1519:22: note: in
      instantiation of template class 'std::__1::__void_pointer<int,
      std::__1::allocator<int &>, false>' requested here
    typedef typename __void_pointer<pointer, allocator_type>::type void_pointer;
                     ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:325:22: note: in
      instantiation of template class
      'std::__1::allocator_traits<std::__1::allocator<int &> >' requested here
    typedef typename __alloc_traits::size_type       size_type;
                     ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:448:15: note: in
      instantiation of template class 'std::__1::__vector_base<int &,
      std::__1::allocator<int &> >' requested here
    : private __vector_base<_Tp, _Allocator>
              ^
referror2.cpp:7:20: note: in instantiation of template class
      'std::__1::vector<int &, std::__1::allocator<int &> >' requested here
    std::vector<T> elems;
                   ^
referror2.cpp:22:18: note: in instantiation of template class
      'Arr<int &, &size>' requested here
  Arr<int&,size> y; // compile-time ERROR deep in the code of class std:...
                 ^
In file included from referror2.cpp:1:
In file included from /usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:266:
In file included from /usr/local/Cellar/llvm/6.0.0/include/c++/v1/__bit_reference:15:
In file included from /usr/local/Cellar/llvm/6.0.0/include/c++/v1/algorithm:643:
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/memory:850:22: error: type 'int'
      cannot be used prior to '::' because it has no members
    typedef typename _Tp::template rebind<_Up> type;
                     ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/memory:954:26: note: in
      instantiation of template class 'std::__1::__pointer_traits_rebind<int,
      const void, false>' requested here
    template <class _Up> using rebind = typename __pointer_traits_rebind...
                         ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/memory:1095:53: note: in
      instantiation of template type alias 'rebind' requested here
    typedef typename pointer_traits<_Ptr>::template rebind<const void> type;
                                                    ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/memory:1520:22: note: in
      instantiation of template class 'std::__1::__const_void_pointer<int,
      std::__1::allocator<int &>, false>' requested here
    typedef typename __const_void_pointer<pointer, allocator_type>::typ...
                     ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:325:22: note: in
      instantiation of template class
      'std::__1::allocator_traits<std::__1::allocator<int &> >' requested here
    typedef typename __alloc_traits::size_type       size_type;
                     ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:448:15: note: in
      instantiation of template class 'std::__1::__vector_base<int &,
      std::__1::allocator<int &> >' requested here
    : private __vector_base<_Tp, _Allocator>
              ^
referror2.cpp:7:20: note: in instantiation of template class
      'std::__1::vector<int &, std::__1::allocator<int &> >' requested here
    std::vector<T> elems;
                   ^
referror2.cpp:22:18: note: in instantiation of template class
      'Arr<int &, &size>' requested here
  Arr<int&,size> y; // compile-time ERROR deep in the code of class std:...
                 ^
In file included from referror2.cpp:1:
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:457:30: error: 
      '__alloc_traits' is a protected member of 'std::__1::__vector_base<int &,
      std::__1::allocator<int &> >'
    typedef typename __base::__alloc_traits          __alloc_traits;
                             ^
referror2.cpp:7:20: note: in instantiation of template class
      'std::__1::vector<int &, std::__1::allocator<int &> >' requested here
    std::vector<T> elems;
                   ^
referror2.cpp:22:18: note: in instantiation of template class
      'Arr<int &, &size>' requested here
  Arr<int&,size> y; // compile-time ERROR deep in the code of class std:...
                 ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:322:54: note: declared
      protected here
    typedef allocator_traits<allocator_type>         __alloc_traits;
                                                     ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:458:30: error: 'reference' is
      a protected member of 'std::__1::__vector_base<int &,
      std::__1::allocator<int &> >'
    typedef typename __base::reference               reference;
                             ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:323:54: note: declared
      protected here
    typedef value_type&                              reference;
                                                     ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:459:30: error: 
      'const_reference' is a protected member of 'std::__1::__vector_base<int &,
      std::__1::allocator<int &> >'
    typedef typename __base::const_reference         const_reference;
                             ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:324:54: note: declared
      protected here
    typedef const value_type&                        const_reference;
                                                     ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:460:30: error: 'size_type' is
      a protected member of 'std::__1::__vector_base<int &,
      std::__1::allocator<int &> >'
    typedef typename __base::size_type               size_type;
                             ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:325:54: note: declared
      protected here
    typedef typename __alloc_traits::size_type       size_type;
                                                     ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:461:30: error: 
      'difference_type' is a protected member of 'std::__1::__vector_base<int &,
      std::__1::allocator<int &> >'
    typedef typename __base::difference_type         difference_type;
                             ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:326:54: note: declared
      protected here
    typedef typename __alloc_traits::difference_type difference_type;
                                                     ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:462:30: error: 'pointer' is a
      protected member of 'std::__1::__vector_base<int &,
      std::__1::allocator<int &> >'
    typedef typename __base::pointer                 pointer;
                             ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:327:54: note: declared
      protected here
    typedef typename __alloc_traits::pointer         pointer;
                                                     ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:463:30: error: 
      'const_pointer' is a protected member of 'std::__1::__vector_base<int &,
      std::__1::allocator<int &> >'
    typedef typename __base::const_pointer           const_pointer;
                             ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:328:54: note: declared
      protected here
    typedef typename __alloc_traits::const_pointer   const_pointer;
                                                     ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:671:15: error: 'data'
      declared as a pointer to a reference of type 'std::__1::vector<int &,
      std::__1::allocator<int &> >::value_type' (aka 'int &')
    value_type*       data() _NOEXCEPT
              ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:674:21: error: 'data'
      declared as a pointer to a reference of type 'std::__1::vector<int &,
      std::__1::allocator<int &> >::value_type' (aka 'int &')
    const value_type* data() const _NOEXCEPT
                    ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:691:36: error: multiple
      overloads of 'push_back' instantiate to the same signature 'void
      (std::__1::vector<int &, std::__1::allocator<int &> >::value_type &)'
    _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x);
                                   ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:688:36: note: previous
      declaration is here
    _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
                                   ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:708:14: error: multiple
      overloads of 'insert' instantiate to the same signature
      'std::__1::vector<int &, std::__1::allocator<int &> >::iterator
      (std::__1::vector<int &, std::__1::allocator<int &> >::const_iterator,
      std::__1::vector<int &, std::__1::allocator<int &> >::value_type &)' (aka
      '__wrap_iter<int> (__wrap_iter<int>, int &)')
    iterator insert(const_iterator __position, value_type&& __x);
             ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/vector:705:14: note: previous
      declaration is here
    iterator insert(const_iterator __position, const_reference __x);
             ^
17 errors generated.
\r
$ g++-8 referror2.cpp -std=c++03  -Wall
In file included from /usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/x86_64-apple-darwin17.5.0/bits/c++allocator.h:33,
                 from /usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/allocator.h:46,
                 from /usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/vector:61,
                 from referror2.cpp:1:
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/ext/new_allocator.h: In instantiation of 'class __gnu_cxx::new_allocator<int&>':
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/allocator.h:108:11:   required from 'class std::allocator<int&>'
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:84:21:   required from 'struct std::_Vector_base<int&, std::allocator<int&> >'
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:339:11:   required from 'class std::vector<int&, std::allocator<int&> >'
referror2.cpp:7:20:   required from 'class Arr<int&, size>'
referror2.cpp:22:18:   required from here
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/ext/new_allocator.h:63:26: error:forming pointer to reference type 'int&'
       typedef _Tp*       pointer;
                          ^~~~~~~
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/ext/new_allocator.h:64:26: error:forming pointer to reference type 'int&'
       typedef const _Tp* const_pointer;
                          ^~~~~~~~~~~~~
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/ext/new_allocator.h:65:26: error:forming reference to reference type 'int&'
       typedef _Tp&       reference;
                          ^~~~~~~~~
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/ext/new_allocator.h:66:26: error:forming reference to reference type 'int&'
       typedef const _Tp& const_reference;
                          ^~~~~~~~~~~~~~~
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/ext/new_allocator.h:145:7: error:forming reference to reference type 'int&'
       construct(pointer __p, const _Tp& __val)
       ^~~~~~~~~
In file included from /usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/vector:61,
                 from referror2.cpp:1:
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/allocator.h: In instantiation of 'class std::allocator<int&>':
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:84:21:   required from 'struct std::_Vector_base<int&, std::allocator<int&> >'
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:339:11:   required from 'class std::vector<int&, std::allocator<int&> >'
referror2.cpp:7:20:   required from 'class Arr<int&, size>'
referror2.cpp:22:18:   required from here
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/allocator.h:113:26: error: forming pointer to reference type 'int&'
       typedef _Tp*       pointer;
                          ^~~~~~~
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/allocator.h:114:26: error: forming pointer to reference type 'int&'
       typedef const _Tp* const_pointer;
                          ^~~~~~~~~~~~~
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/allocator.h:115:26: error: forming reference to reference type 'int&'
       typedef _Tp&       reference;
                          ^~~~~~~~~
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/allocator.h:116:26: error: forming reference to reference type 'int&'
       typedef const _Tp& const_reference;
                          ^~~~~~~~~~~~~~~
In file included from /usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/vector:64,
                 from referror2.cpp:1:
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h: In instantiation of 'class std::vector<int&, std::allocator<int&> >':
referror2.cpp:7:20:   required from 'class Arr<int&, size>'
referror2.cpp:22:18:   required from here
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:379:20: error: no members matching 'std::vector<int&, std::allocator<int&> >::_Base {aka std::_Vector_base<int&, std::allocator<int&> >}::_M_allocate' in 'std::vector<int&, std::allocator<int&> >::_Base' {aka 'struct std::_Vector_base<int&, std::allocator<int&> >'}
       using _Base::_M_allocate;
                    ^~~~~~~~~~~
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:380:20: error: no members matching 'std::vector<int&, std::allocator<int&> >::_Base {aka std::_Vector_base<int&, std::allocator<int&> >}::_M_deallocate' in 'std::vector<int&, std::allocator<int&> >::_Base' {aka 'struct std::_Vector_base<int&, std::allocator<int&> >'}
       using _Base::_M_deallocate;
                    ^~~~~~~~~~~~~
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:441:7: error: forming reference to reference type 'std::vector<int&, std::allocator<int&> >::value_type' {aka 'int&'}
       vector(size_type __n, const value_type& __value = value_type(),
       ^~~~~~
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:636:7: error: forming reference to reference type 'std::vector<int&, std::allocator<int&> >::value_type' {aka 'int&'}
       assign(size_type __n, const value_type& __val)
       ^~~~~~
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:1055:7: error: forming pointer to reference type 'int&'
       data() _GLIBCXX_NOEXCEPT
       ^~~~
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:1059:7: error: forming pointer to reference type 'int&'
       data() const _GLIBCXX_NOEXCEPT
       ^~~~
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:1074:7: error: forming reference to reference type 'std::vector<int&, std::allocator<int&> >::value_type' {aka 'int&'}
       push_back(const value_type& __x)
       ^~~~~~~~~
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:1243:7: error: forming reference to reference type 'std::vector<int&, std::allocator<int&> >::value_type' {aka 'int&'}
       insert(iterator __position, size_type __n, const value_type& __x)
       ^~~~~~
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:1472:7: error: forming reference to reference type 'std::vector<int&, std::allocator<int&> >::value_type' {aka 'int&'}
       _M_fill_initialize(size_type __n, const value_type& __value)
       ^~~~~~~~~~~~~~~~~~
In file included from /usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/vector:69,
                 from referror2.cpp:1:
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/vector.tcc:245:5: error: forming reference to reference type 'std::vector<int&, std::allocator<int&> >::value_type' {aka 'int&'}
     vector<_Tp, _Alloc>::
     ^~~~~~~~~~~~~~~~~~~
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/vector.tcc:478:5: error: forming reference to reference type 'std::vector<int&, std::allocator<int&> >::value_type' {aka 'int&'}
     vector<_Tp, _Alloc>::
     ^~~~~~~~~~~~~~~~~~~
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/vector.tcc:387:5: error: forming reference to reference type 'int&'
     vector<_Tp, _Alloc>::
     ^~~~~~~~~~~~~~~~~~~
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/vector.tcc:418:5: error: forming reference to reference type 'int&'
     vector<_Tp, _Alloc>::
     ^~~~~~~~~~~~~~~~~~~
In file included from /usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/vector:64,
                 from referror2.cpp:1:
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:1716:2: error: forming pointer to reference type 'std::vector<int&, std::allocator<int&> >::value_type' {aka 'int&'}
  _M_data_ptr(_Ptr __ptr)
  ^~~~~~~~~~~
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:1721:2: error: forming pointer to reference type 'std::vector<int&, std::allocator<int&> >::value_type' {aka 'int&'}
  _M_data_ptr(_Ptr __ptr) const
  ^~~~~~~~~~~
referror2.cpp: In instantiation of 'Arr<T, SZ>::Arr() [with T = int&; int& SZ = size]':
referror2.cpp:22:18:   required from here
referror2.cpp:9:21: error: no matching function for call to 'std::vector<int&, std::allocator<int&> >::vector(int&)'
     Arr() : elems(SZ) {           // use current SZ as initial vector size
                     ^
In file included from /usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/vector:64,
                 from referror2.cpp:1:
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:549:2: note: candidate: 'template<class _InputIterator> std::vector<_Tp, _Alloc>::vector(_InputIterator, _InputIterator, const allocator_type&)'
  vector(_InputIterator __first, _InputIterator __last,
  ^~~~~~
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:549:2: note:   template argument deduction/substitution failed:
referror2.cpp:9:21: note:   candidate expects 3 arguments, 1 provided
     Arr() : elems(SZ) {           // use current SZ as initial vector size
                     ^
In file included from /usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/vector:64,
                 from referror2.cpp:1:
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:458:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = int&; _Alloc = std::allocator<int&>]'
       vector(const vector& __x)
       ^~~~~~
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:458:7: note:   no known conversion for argument 1 from 'int' to 'const std::vector<int&, std::allocator<int&> >&'
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:402:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(const allocator_type&) [with _Tp = int&; _Alloc = std::allocator<int&>; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<int&>]'
       vector(const allocator_type& __a) _GLIBCXX_NOEXCEPT
       ^~~~~~
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:402:7: note:   no known conversion for argument 1 from 'int' to 'const allocator_type&' {aka 'const std::allocator<int&>&'}
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:391:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector() [with _Tp = int&; _Alloc = std::allocator<int&>]'
       vector()
       ^~~~~~
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:391:7: note:   candidate expects 0 arguments, 1 provided
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h: In instantiation of 'std::vector<_Tp, _Alloc>::~vector() [with _Tp = int&; _Alloc = std::allocator<int&>]':
referror2.cpp:5:7:   required from here
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:567:30: error: struct std::_Vector_base<int&, std::allocator<int&> >::_Vector_impl' has no member named '_M_start'
  std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
                ~~~~~~~~~~~~~~^~~~~~~~
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:567:54: error: struct std::_Vector_base<int&, std::allocator<int&> >::_Vector_impl' has no member named '_M_finish'
  std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
                                        ~~~~~~~~~~~~~~^~~~~~~~~
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h: In instantiation of 'std::_Vector_base<_Tp, _Alloc>::~_Vector_base() [with _Tp = int&; _Alloc = std::allocator<int&>]':
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:570:7:   required from 'std::vector<_Tp, _Alloc>::~vector() [with _Tp = int&; _Alloc = std::allocator<int&>]'
referror2.cpp:5:7:   required from here
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:285:24: error: struct std::_Vector_base<int&, std::allocator<int&> >::_Vector_impl' has no member named '_M_start'
  _M_deallocate(_M_impl._M_start,
                ~~~~~~~~^~~~~~~~
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:286:17: error: struct std::_Vector_base<int&, std::allocator<int&> >::_Vector_impl' has no member named '_M_end_of_storage'
         _M_impl._M_end_of_storage - _M_impl._M_start);
         ~~~~~~~~^~~~~~~~~~~~~~~~~
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:286:45: error: struct std::_Vector_base<int&, std::allocator<int&> >::_Vector_impl' has no member named '_M_start'
         _M_impl._M_end_of_storage - _M_impl._M_start);
                                     ~~~~~~~~^~~~~~~~
\r
$ g++-8 referror2.cpp -std=c++2a  -Wall
In file included from /usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/x86_64-apple-darwin17.5.0/bits/c++allocator.h:33,
                 from /usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/allocator.h:46,
                 from /usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/vector:61,
                 from referror2.cpp:1:
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/ext/new_allocator.h: In instantiation of 'class __gnu_cxx::new_allocator<int&>':
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/allocator.h:108:11:   required from 'class std::allocator<int&>'
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:84:21:   required from 'struct std::_Vector_base<int&, std::allocator<int&> >'
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:339:11:   required from 'class std::vector<int&, std::allocator<int&> >'
referror2.cpp:7:20:   required from 'class Arr<int&, size>'
referror2.cpp:22:18:   required from here
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/ext/new_allocator.h:63:26: error:forming pointer to reference type 'int&'
       typedef _Tp*       pointer;
                          ^~~~~~~
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/ext/new_allocator.h:64:26: error:forming pointer to reference type 'int&'
       typedef const _Tp* const_pointer;
                          ^~~~~~~~~~~~~
In file included from /usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/vector:61,
                 from referror2.cpp:1:
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/allocator.h: In instantiation of 'class std::allocator<int&>':
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:84:21:   required from 'struct std::_Vector_base<int&, std::allocator<int&> >'
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:339:11:   required from 'class std::vector<int&, std::allocator<int&> >'
referror2.cpp:7:20:   required from 'class Arr<int&, size>'
referror2.cpp:22:18:   required from here
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/allocator.h:113:26: error: forming pointer to reference type 'int&'
       typedef _Tp*       pointer;
                          ^~~~~~~
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/allocator.h:114:26: error: forming pointer to reference type 'int&'
       typedef const _Tp* const_pointer;
                          ^~~~~~~~~~~~~
In file included from /usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/ext/alloc_traits.h:36,
                 from /usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_construct.h:61,
                 from /usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/vector:62,
                 from referror2.cpp:1:
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/alloc_traits.h: In instantiation of 'struct std::allocator_traits<std::allocator<int&> >':
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/ext/alloc_traits.h:50:10:   required from 'struct __gnu_cxx::__alloc_traits<std::allocator<int&>, int&>'
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:84:21:   required from 'struct std::_Vector_base<int&, std::allocator<int&> >'
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:339:11:   required from 'class std::vector<int&, std::allocator<int&> >'
referror2.cpp:7:20:   required from 'class Arr<int&, size>'
referror2.cpp:22:18:   required from here
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/alloc_traits.h:392:27: error: forming pointer to reference type 'int&'
       using pointer = _Tp*;
                           ^
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/alloc_traits.h:395:39: error: forming pointer to reference type 'int&'
       using const_pointer = const _Tp*;
                                       ^
In file included from /usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_construct.h:61,
                 from /usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/vector:62,
                 from referror2.cpp:1:
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/ext/alloc_traits.h: In instantiation of 'struct __gnu_cxx::__alloc_traits<std::allocator<int&>, int&>':
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:84:21:   required from 'struct std::_Vector_base<int&, std::allocator<int&> >'
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:339:11:   required from 'class std::vector<int&, std::allocator<int&> >'
referror2.cpp:7:20:   required from 'class Arr<int&, size>'
referror2.cpp:22:18:   required from here
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/ext/alloc_traits.h:66:23: error: no members matching '__gnu_cxx::__alloc_traits<std::allocator<int&>, int&>::_Base_type {aka std::allocator_traits<std::allocator<int&> >}::allocate' in '__gnu_cxx::__alloc_traits<std::allocator<int&>, int&>::_Base_type' {aka 'struct std::allocator_traits<std::allocator<int&> >'}
     using _Base_type::allocate;
                       ^~~~~~~~
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/ext/alloc_traits.h:67:23: error: no members matching '__gnu_cxx::__alloc_traits<std::allocator<int&>, int&>::_Base_type {aka std::allocator_traits<std::allocator<int&> >}::deallocate' in '__gnu_cxx::__alloc_traits<std::allocator<int&>, int&>::_Base_type' {aka 'struct std::allocator_traits<std::allocator<int&> >'}
     using _Base_type::deallocate;
                       ^~~~~~~~~~
In file included from /usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/vector:64,
                 from referror2.cpp:1:
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h: In instantiation of 'class std::vector<int&, std::allocator<int&> >':
referror2.cpp:7:20:   required from 'class Arr<int&, size>'
referror2.cpp:22:18:   required from here
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:379:20: error: no members matching 'std::vector<int&, std::allocator<int&> >::_Base {aka std::_Vector_base<int&, std::allocator<int&> >}::_M_allocate' in 'std::vector<int&, std::allocator<int&> >::_Base' {aka 'struct std::_Vector_base<int&, std::allocator<int&> >'}
       using _Base::_M_allocate;
                    ^~~~~~~~~~~
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:380:20: error: no members matching 'std::vector<int&, std::allocator<int&> >::_Base {aka std::_Vector_base<int&, std::allocator<int&> >}::_M_deallocate' in 'std::vector<int&, std::allocator<int&> >::_Base' {aka 'struct std::_Vector_base<int&, std::allocator<int&> >'}
       using _Base::_M_deallocate;
                    ^~~~~~~~~~~~~
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:1055:7: error: forming pointer to reference type 'int&'
       data() _GLIBCXX_NOEXCEPT
       ^~~~
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:1059:7: error: forming pointer to reference type 'int&'
       data() const _GLIBCXX_NOEXCEPT
       ^~~~
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:1090:7: error: void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = int&; _Alloc = std::allocator<int&>; std::vector<_Tp, _Alloc>::value_type = int&]' cannot be overloaded with 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int&; _Alloc = std::allocator<int&>; std::vector<_Tp, _Alloc>::value_type = int&]'
       push_back(value_type&& __x)
       ^~~~~~~~~
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:1074:7: note: previous declaration 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int&; _Alloc = std::allocator<int&>; std::vector<_Tp, _Alloc>::value_type = int&]'
       push_back(const value_type& __x)
       ^~~~~~~~~
In file included from /usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/utility:76,
                 from /usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_uninitialized.h:60,
                 from /usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/vector:63,
                 from referror2.cpp:1:
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/initializer_list: In instantiation of 'class std::initializer_list<int&>':
referror2.cpp:9:21:   required from 'Arr<T, SZ>::Arr() [with T = int&; int& SZ = size]'
referror2.cpp:22:18:   required from here
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/initializer_list:54:26: error: forming pointer to reference type 'int&'
       typedef const _E*  iterator;
                          ^~~~~~~~
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/initializer_list:55:26: error: forming pointer to reference type 'int&'
       typedef const _E*  const_iterator;
                          ^~~~~~~~~~~~~~
In file included from /usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/vector:64,
                 from referror2.cpp:1:
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h: In instantiation of 'std::vector<_Tp, _Alloc>::~vector() [with _Tp = int&; _Alloc = std::allocator<int&>]':
referror2.cpp:5:7:   required from here
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:567:30: error: struct std::_Vector_base<int&, std::allocator<int&> >::_Vector_impl' has no member named '_M_start'
  std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
                ~~~~~~~~~~~~~~^~~~~~~~
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:567:54: error: struct std::_Vector_base<int&, std::allocator<int&> >::_Vector_impl' has no member named '_M_finish'
  std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
                                        ~~~~~~~~~~~~~~^~~~~~~~~
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h: In instantiation of 'std::_Vector_base<_Tp, _Alloc>::~_Vector_base() [with _Tp = int&; _Alloc = std::allocator<int&>]':
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:570:7:   required from 'std::vector<_Tp, _Alloc>::~vector() [with _Tp = int&; _Alloc = std::allocator<int&>]'
referror2.cpp:5:7:   required from here
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:285:24: error: struct std::_Vector_base<int&, std::allocator<int&> >::_Vector_impl' has no member named '_M_start'
  _M_deallocate(_M_impl._M_start,
                ~~~~~~~~^~~~~~~~
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:286:17: error: struct std::_Vector_base<int&, std::allocator<int&> >::_Vector_impl' has no member named '_M_end_of_storage'
         _M_impl._M_end_of_storage - _M_impl._M_start);
         ~~~~~~~~^~~~~~~~~~~~~~~~~
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/bits/stl_vector.h:286:45: error: struct std::_Vector_base<int&, std::allocator<int&> >::_Vector_impl' has no member named '_M_start'
         _M_impl._M_end_of_storage - _M_impl._M_start);
                                     ~~~~~~~~^~~~~~~~

まとめ

cpp clang++ g++
=-std=c++03 =-std=c++2a =-std=c++03 =-std=c++2a
referror2 15 17 30 20

検討事項(agenda)

1)コンパイルエラーをなくす修正方法
clang++ -std=c++2aの方がエラーが多い。
2)役に立つまたは意味のあるその他の出力

参考資料(reference)

docker gnu(gcc/g++) and llvm(clang/clang++)
https://qiita.com/drafts/059874ea39c4de64c0f7

[C][C++]の国際規格案の例題をコンパイルするときの課題7つ。
https://qiita.com/kaizen_nagoya/items/5f4b155030259497c4de

C++N4606 Working Draft 2016, ISO/IEC 14882, C++ standardのコード断片をコンパイルするためにしていること
https://qiita.com/kaizen_nagoya/items/a8d7ee2f2e29e76c19c1

コンパイル用shell script C版(clangとgcc)とC++版(clang++とg++)
https://qiita.com/kaizen_nagoya/items/74220c0577a512c2d7da

Clang/Clang++(LLVM) gcc/g++(GNU) コンパイラ警告等比較
https://qiita.com/kaizen_nagoya/items/9a82b958cc3aeef0403f

C++2003とC++2017でコンパイルエラーになるならない事例集
https://qiita.com/kaizen_nagoya/items/a13ea3823441c430edff

Qiitaに投稿するCのStyle例(暫定)
https://qiita.com/kaizen_nagoya/items/946df1528a6a1ef2bc0d

cpprefjpのdecltypeをコンパイル試験
https://qiita.com/kaizen_nagoya/items/090909af702f0d5d8a67

MISRA C++ 5-0-16
https://qiita.com/kaizen_nagoya/items/7df2d4e05db724752a74

C++ Templates Part1 BASICS Chapter 3. Class Templates 3.2 Use of Class Template Stack stack1test.cpp
https://qiita.com/kaizen_nagoya/items/cd5fc49106fad5a4e9ed

ISO/IEC TS 17961:2013 C Secure Coding Rules(1) All list(to be confirmed)
https://qiita.com/kaizen_nagoya/items/54e056195c4f11b850a1

C言語(C++)に対する誤解、曲解、無理解、爽快。
https://qiita.com/kaizen_nagoya/items/3f3992c9722c1cee2e3a

C Puzzle Bookの有り難み5つ、C言語規格及びCコンパイラの特性を認識
https://qiita.com/kaizen_nagoya/items/d89a48c1536a02ecdec9

'wchar.h' file not found で困った clang++ macOS
https://qiita.com/kaizen_nagoya/items/de15cd46d657517fac11

Open POSIX Test Suiteの使い方を調べはじめました
https://qiita.com/kaizen_nagoya/items/644d5e407f5faf96e6dc

MISRA-C 2012 Referenceに掲載している文献の入手可能性を確認
https://qiita.com/kaizen_nagoya/items/96dc8b125e462d5575bb

どうやって MISRA Example Suiteをコンパイルするか
https://qiita.com/kaizen_nagoya/items/fbdbff5ff696e2ca7f00

MISRA C まとめ #include
https://qiita.com/kaizen_nagoya/items/f1a79a7cbd281607c7c9

「C++完全理解ガイド」の同意できること上位10
https://qiita.com/kaizen_nagoya/items/aa5744e0c4a8618c7671

文書履歴(document history)

ver. 0.10 初稿 20180515 コンパイルエラーが取れていない。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0