https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70106
Bug ID: 70106
Summary: [4.9/5.3/6.0][C++11 or above] adding parenthesis [cerr
<< (var)] cause error: invalid static_cast from type
'const size_t {aka const long unsigned int}' to type
'size_t& {aka long unsigned int&}'
Product: gcc
Version: 6.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: david.abdurachmanov at gmail dot com
Target Milestone: ---
Created attachment 37878
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=37878&action=edit
test case
I came across this while recompiling our repositories with GCC 6.0.0 (r233941,
a couple of days old already). Only happens with C++11 or above. Seems to
affect GCC 4.9.3, 5.3.0, and GCC 6.0.0. Works fine with Clang 3.7.0 and the
latest version of ICC (16.0.2 20160204).
I did run C-Reduce and then did some additional manual minimisation.
Test case attached.
### COMPILING ###
g++ -std=c++14 -Wno-deprecated -c ratext_worker_min_new.cpp -fPIC -o
ratext_worker.o
### ERROR ###
ratext_worker_min_new.cpp: In instantiation of ‘const int&
momentum_configuration< <template-parameter-1-1> >::p(size_t) const [with
<template-parameter-1-1> = int; size_t = long unsigned int]’:
ratext_worker_min_new.cpp:22:25: required from ‘void momentum_configuration<
<template-parameter-1-1> >::mom(size_t) [with <template-parameter-1-1> = int;
size_t = long unsigned int]’
ratext_worker_min_new.cpp:53:3: required from ‘void triangle_Rat_plusminus<
<template-parameter-1-1>,
RatTriSpecs>::get_sub_terms_work(momentum_configuration<T>&, const
std::vector<int>&, triangle_param<T, RatTriSpecs:: MUBUBPOINTS, RatTriSpecs::
YPOINTS>&) [with T = int; <template-parameter-1-1> = rat_worker; RatTriSpecs =
Higgs_RatTri_Specification<rat_worker>]’
ratext_worker_min_new.cpp:58:50: required from here
ratext_worker_min_new.cpp:28:13: error: invalid static_cast from type ‘const
size_t {aka const long unsigned int}’ to type ‘size_t& {aka long unsigned
int&}’
std::cerr << (momentum_configuration::nbr);
^
### EXPECTATIONS ###
The issue is this line:
28 std::cerr << (momentum_configuration::nbr);
Removing parenthesis resolves the issue:
28 std::cerr << momentum_configuration::nbr;
Clang and ICC compile the code in C++14 with and without the parenthesis.