From: tf on
Seungbeom Kim <musiphil(a)bawi.org> wrote:
> On 2010-04-01 14:56, Paul Bibbings wrote:
>> Seungbeom Kim<musiphil(a)bawi.org> writes:
>>
>>> I get this warning while compiling the program below with g++-4.4.3:
>>>
>>> $ g++ -O2 -Wall test.cc
>>> test.cc: In function ???int main()???:
>>> test:8: warning: dereferencing pointer ???<anonymous>??? does break
>>> strict-aliasing rules
>>> /usr/include/c++/4.4/bits/stl_list.h:214: note: initialized from here
>
> Turning off that optimization could be an answer, but I???d like to
> know whether the warning is just a false positive or it really means
> I risk some undefined behaviour and I should do something (turn the
> optimization off or change the code somehow).

"does" means you *are* violating the rules. g++ says "may" (IIRC, maybe
"can") when it can't figure out for sure.

I think there are different levels of strict aliasing checking. See
the manpage.

FWIW, I just disable strict aliasing on all C++ code I write. AFAICT,
strict aliasing was for C, g++ is just (incorrectly?) applying it to
C++. Further, these aliasing concerns are exactly why we have the
valarray header, and so it seems dumb in C++: if it was critical for
performance that my data didn't alias, I would use valarray. If I'm
not, then why would my compiler assume my variables didn't alias?

I've never brought this up on gcc-help; it's possible I'm missing
something.

-tom

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Mathias Gaunard on
On 1 avr, 15:08, Seungbeom Kim <musip...(a)bawi.org> wrote:
> I get this warning while compiling the program below with g++-4.4.3:
>
> $ g++ -O2 -Wall test.cc
> test.cc: In function �int main()�:
> test:8: warning: dereferencing pointer �<anonymous>� does break strict-aliasing
> rules
> /usr/include/c++/4.4/bits/stl_list.h:214: note: initialized from here
>
> I don�t see anything suspicious in the following program, but there
> should be a reason for the warning. Can anyone explain this?

There is no cast, therefore there should be no problem.
Report this issue to the GCC guys.


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Seungbeom Kim on
On 2010-04-03 13:34, Mathias Gaunard wrote:
> On 1 avr, 15:08, Seungbeom Kim<musip...(a)bawi.org> wrote:
>> I get this warning while compiling the program below with g++-4.4.3:
>>
>> $ g++ -O2 -Wall test.cc
>> test.cc: In function �int main()�:
>> test:8: warning: dereferencing pointer �<anonymous>� does break strict-aliasing
>> rules
>> /usr/include/c++/4.4/bits/stl_list.h:214: note: initialized from here
>>
>> I don�t see anything suspicious in the following program, but there
>> should be a reason for the warning. Can anyone explain this?
>
> There is no cast, therefore there should be no problem.

Actually there is one at stl_list.h:214, though that is just a downcast
and I doubt it should actually be a problem.

--
Seungbeom Kim

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Joshua Maurice on
On Apr 2, 6:25 pm, t...(a)shigeru.sci.utah.edu wrote:
> Seungbeom Kim <musip...(a)bawi.org> wrote:
> > On 2010-04-01 14:56, Paul Bibbings wrote:
> >> Seungbeom Kim<musip...(a)bawi.org> writes:
>
> >>> I get this warning while compiling the program below with g++-4.4.3:
>
> >>> $ g++ -O2 -Wall test.cc
> >>> test.cc: In function ???int main()???:
> >>> test:8: warning: dereferencing pointer ???<anonymous>??? does break
> >>> strict-aliasing rules
> >>> /usr/include/c++/4.4/bits/stl_list.h:214: note: initialized from here
>
> > Turning off that optimization could be an answer, but I???d like to
> > know whether the warning is just a false positive or it really means
> > I risk some undefined behaviour and I should do something (turn the
> > optimization off or change the code somehow).
>
> "does" means you *are* violating the rules. g++ says "may" (IIRC, maybe
> "can") when it can't figure out for sure.
>
> I think there are different levels of strict aliasing checking. See
> the manpage.
>
> FWIW, I just disable strict aliasing on all C++ code I write. AFAICT,
> strict aliasing was for C, g++ is just (incorrectly?) applying it to
> C++.

INCITS+ISO+IEC+14882-2003
C++03 standard.
3.10 Lvalues and rvalues / 15

If a program attempts to access the stored value of an object through
an lvalue of other than one of the following
types the behavior is undefined48):
� the dynamic type of the object,
� a cv-qualified version of the dynamic type of the object,
� a type that is the signed or unsigned type corresponding to the
dynamic type of the object,
� a type that is the signed or unsigned type corresponding to a cv-
qualified version of the dynamic type of
the object,
� an aggregate or union type that includes one of the aforementioned
types among its members (including,
recursively, a member of a subaggregate or contained union),
� a type that is a (possibly cv-qualified) base class type of the
dynamic type of the object,
� a char or unsigned char type.
__________________
48) The intent of this list is to specify those circumstances in which
an object may or may not be aliased.


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]