This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/85717] New: anonymous union in initializer list : do not handle the types correctly
- From: "daffra.claudio at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 09 May 2018 15:22:59 +0000
- Subject: [Bug c++/85717] New: anonymous union in initializer list : do not handle the types correctly
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85717
Bug ID: 85717
Summary: anonymous union in initializer list : do not handle
the types correctly
Product: gcc
Version: 5.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: daffra.claudio at gmail dot com
Target Milestone: ---
Created attachment 44100
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44100&action=edit
anonymous union in initializer list : do not handle the types correctly
anonymous union in initializer list : do not handle the types correctly
when i use initializer list in anonyumouse union, g++ gives this error code
more or less i expected;
C:\prj\cd>g++ src\prova.cpp -o prova.exe -std=c++14
src\prova.cpp: In function 'int main()':
src\prova.cpp:31:5: error: narrowing conversion of
'3.3999999999999999e+0' from 'double' to 'uint64_t {aka long long unsigned
int}' inside { } [-Wnarrowing]
t1 = { 1 ,"a",3.4 } ;
^
indeed in a normal way, code below all works o perfectly
t1.real = 6.6 ;
std::cout << t1.real << "\n" ;
t1.integer = 3 ;
std::cout << t1.integer << "\n" ;
despite result change if i swith union member
union {
uint64_t integer ;
double real;
} ;
i put
union {
double real;
uint64_t integer ;
} ;
source code error
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdint.h>
#include <assert.h>
typedef struct token_s
{
uint8_t sym ;
std::string tok ;
union {
double real;
uint64_t integer ;
} ;
} token_t ;
int main ( void )
{
assert ( sizeof(uint64_t)==sizeof(double) ) ;
token_t t1 ;
t1.real = 6.6 ;
std::cout << t1.real << "\n" ;
t1.integer = 3 ;
std::cout << t1.integer << "\n" ;
t1 = { 1 ,"a",3.4 } ;
std::cout << t1.real << "\n" ;
t1 = { 1 ,"a",2 } ;
std::cout << t1.integer << "\n" ;
return 0 ;
}