This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/86556] <random>, most vexing parse, and diagnostic output


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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I think this can be considered a duplicate of PR 25814, because if you got a
warning for:

        std::mt19937 gen(std::random_device());

Then the later errors should make more sense.

Clang's output for the same code is:

vex.cc:3:25: warning: parentheses were disambiguated as a function declaration
[-Wvexing-parse]
        std::mt19937 gen(std::random_device());
                        ^~~~~~~~~~~~~~~~~~~~~~
vex.cc:3:26: note: add a pair of parentheses to declare a variable
        std::mt19937 gen(std::random_device());
                         ^
                         (                   )
In file included from vex.cc:1:
In file included from
/usr/lib/gcc/x86_64-redhat-linux/7/../../../../include/c++/7/random:51:
/usr/lib/gcc/x86_64-redhat-linux/7/../../../../include/c++/7/bits/random.tcc:3320:62:
error: member reference base type 'std::mersenne_twister_engine<unsigned long,
32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752,
18, 1812433253> (std::random_device (*)())' is not a structure or union
      const long double __r = static_cast<long double>(__urng.max())
                                                       ~~~~~~^~~~
/usr/lib/gcc/x86_64-redhat-linux/7/../../../../include/c++/7/bits/random.h:183:16:
note: in instantiation of function template specialization
'std::generate_canonical<double, 53, std::mersenne_twister_engine<unsigned
long, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15,
4022730752, 18, 1812433253>
      (std::random_device (*)())>' requested here
          return std::generate_canonical<_DInputType,
                      ^
/usr/lib/gcc/x86_64-redhat-linux/7/../../../../include/c++/7/bits/random.h:3562:7:
note: in instantiation of member function
'std::__detail::_Adaptor<std::mersenne_twister_engine<unsigned long, 32, 624,
397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18,
1812433253> (std::random_device (*)()),
      double>::operator()' requested here
        if ((__aurng() - __aurng.min())
             ^
/usr/lib/gcc/x86_64-redhat-linux/7/../../../../include/c++/7/bits/random.h:3553:22:
note: in instantiation of function template specialization
'std::bernoulli_distribution::operator()<std::mersenne_twister_engine<unsigned
long, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15,
4022730752, 18,
      1812433253> (std::random_device (*)())>' requested here
      { return this->operator()(__urng, _M_param); }
                     ^
vex.cc:5:17: note: in instantiation of function template specialization
'std::bernoulli_distribution::operator()<std::mersenne_twister_engine<unsigned
long, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15,
4022730752, 18, 1812433253> (std::random_device (*)())>' requested here
        return d(gen);
                ^
1 warning and 1 error generated.


It's not really possible to improve the later errors, because the location of
the invalid code is quite far from the declaration that causes the problem. We
could add a note to any attempt to access members of a function type or
function pointer type saying that you might have been bitten by a vexing parse,
but it wouldn't always be true.

*** This bug has been marked as a duplicate of bug 25814 ***

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]