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]

Re: 2.95.2 Alpha C++ STL <vector> -Wcast-align gives many warnings


Jonathan Thornburg wrote:
> 
> On an alphaev56-dec-osf4.0d system, g++ 2.95.2 -Wcast-align gives many
> warnings "warning: cast increases required alignment of target type"
> when
> compiling programs which use (the STL header file provided with 2.95.2)
> <vector>.

I'm also seeing g++ 2.95.2 -Wcast-align warnings on SunOS 7 (sparc). The
test case is below. The presence of virtual inheritance seems to trigger
the warning, as does the union containing a long long member. The
warning doesn't show up on Linux (i86). Is the alignment requirement of
long long stricter than that of a struct on sparc?

Thanks
martin

$ cat test.cpp

struct A   // reduced from to pthread_mutex_t
{ 
    union {
        char a;
        long long b;
    } u;
};

struct B: virtual public A
{
    bool foo () const {
        return !static_cast<const A*>(this);
    }
};


$ g++ -v
Reading specs from
/usr/local/lib/gcc-lib/sparc-sun-solaris2.7/2.95.2/specs
gcc version 2.95.2 19991024 (release)

$ g++ -c -Wcast-align -c test.cpp
test.cpp: In method `bool B::foo() const':
test.cpp:12: warning: cast increases required alignment of target type


> For example, this program
> 
>    #include <vector>
>    using namespace std;
> 
>    class   gridfn_vector
>            {
>    public:
>            gridfn_vector()
>                    : N_gridfns_(0),
>                      gfns_(0)
>                    { }
>            ~gridfn_vector()
>                    { }
> 
>    private:
>            // we forbid copying and passing by value
>            // by declaring the copy constructor and assignment operator
>            // private, but never defining them
>            gridfn_vector(const gridfn_vector &rhs);
>            gridfn_vector& operator=(const gridfn_vector &rhs);
> 
>    private:
>            int N_gridfns_;
>            vector<int> gfns_;
>            };
> 
> produces the output
> 
>    % /usr/local/apps/gcc-2.95.2/bin/g++ --verbose --save-temps
> -Wcast-align -c alpha.warn.cc
>    Reading specs from
> /usr/local/apps/gcc-2.95.2/lib/gcc-lib/alphaev56-dec-osf4.0d/2.95.2/spec
> s
>    gcc version 2.95.2 19991024 (release)
> 
> /usr/local/apps/gcc-2.95.2/lib/gcc-lib/alphaev56-dec-osf4.0d/2.95.2/cpp
> -lang-c++ -v -D__GNUC__=2 -D__GNUG__=2 -D__GNUC_MINOR__=95 -D__cplusplus
> -Dunix -D__osf__ -D_LONGLONG -DSYSTYPE_BSD -D_SYSTYPE_BSD -D__unix__
> -D__osf__ -D_LONGLONG -D__SYSTYPE_BSD__ -D_SYSTYPE_BSD -D__unix
> -D__SYSTYPE_BSD -Asystem(unix) -Asystem(xpg4) -D__EXCEPTIONS
> -Wcast-align -D__LANGUAGE_C_PLUS_PLUS__ -D__LANGUAGE_C_PLUS_PLUS
> -D__cplusplus -Acpu(alpha) -Amachine(alpha) -D__alpha -D__alpha__
> -D__alpha_ev5__ -Acpu(ev5) -D__alpha_bwx__ -Acpu(bwx) alpha.warn.cc
> alpha.warn.ii
>    GNU CPP version 2.95.2 19991024 (release)
>    #include "..." search starts here:
>    #include <...> search starts here:
> 
> /usr/local/apps/gcc-2.95.2/lib/gcc-lib/alphaev56-dec-osf4.0d/2.95.2/../.
> ./../../include/g++-3
>     /usr/local/include
> 
> /usr/local/apps/gcc-2.95.2/lib/gcc-lib/alphaev56-dec-osf4.0d/2.95.2/../.
> ./../../alphaev56-dec-osf4.0d/include
> 
> /usr/local/apps/gcc-2.95.2/lib/gcc-lib/alphaev56-dec-osf4.0d/2.95.2/incl
> ude
>     /usr/include
>    End of search list.
>    The following default directories have been omitted from the search
> path:
>    End of omitted list.
> 
> /usr/local/apps/gcc-2.95.2/lib/gcc-lib/alphaev56-dec-osf4.0d/2.95.2/cc1p
> lus alpha.warn.ii -quiet -dumpbase alpha.warn.cc -Wcast-align -version
> -o alpha.warn.s
>    GNU C++ version 2.95.2 19991024 (release) (alphaev56-dec-osf4.0d)
> compiled by GNU C version 2.8.1.
> 
> /usr/local/apps/gcc-2.95.2/lib/gcc-lib/alphaev56-dec-osf4.0d/2.95.2/../.
> ./../../include/g++-3/stl_alloc.h: In function `static char *
> __default_alloc_template<false,0>::_S_chunk_alloc(long unsigned int, int
> &)':
> 
> /usr/local/apps/gcc-2.95.2/lib/gcc-lib/alphaev56-dec-osf4.0d/2.95.2/../.
> ./../../include/g++-3/stl_alloc.h:531:   instantiated from
> `__default_alloc_template<false,0>::_S_refill(long unsigned int)'
> 
> /usr/local/apps/gcc-2.95.2/lib/gcc-lib/alphaev56-dec-osf4.0d/2.95.2/../.
> ./../../include/g++-3/stl_alloc.h:419:   instantiated from here
> 
> /usr/local/apps/gcc-2.95.2/lib/gcc-lib/alphaev56-dec-osf4.0d/2.95.2/../.
> ./../../include/g++-3/stl_alloc.h:487: warning: cast increases required
> alignment of target type
> 
> /usr/local/apps/gcc-2.95.2/lib/gcc-lib/alphaev56-dec-osf4.0d/2.95.2/../.
> ./../../include/g++-3/stl_alloc.h:488: warning: cast increases required
> alignment of target type
> 
> /usr/local/apps/gcc-2.95.2/lib/gcc-lib/alphaev56-dec-osf4.0d/2.95.2/../.
> ./../../include/g++-3/stl_alloc.h: In function `static void *
> __default_alloc_template<false,0>::_S_refill(long unsigned int)':
> 
> /usr/local/apps/gcc-2.95.2/lib/gcc-lib/alphaev56-dec-osf4.0d/2.95.2/../.
> ./../../include/g++-3/stl_alloc.h:419:   instantiated from here
> 
> /usr/local/apps/gcc-2.95.2/lib/gcc-lib/alphaev56-dec-osf4.0d/2.95.2/../.
> ./../../include/g++-3/stl_alloc.h:542: warning: cast increases required
> alignment of target type
> 
> /usr/local/apps/gcc-2.95.2/lib/gcc-lib/alphaev56-dec-osf4.0d/2.95.2/../.
> ./../../include/g++-3/stl_alloc.h:543: warning: cast increases required
> alignment of target type
> 
> /usr/local/apps/gcc-2.95.2/lib/gcc-lib/alphaev56-dec-osf4.0d/2.95.2/../.
> ./../../include/g++-3/stl_alloc.h:546: warning: cast increases required
> alignment of target type
>     as -g -nocpp -O0 -o alpha.warn.o alpha.warn.s
> 
> /usr/local/apps/gcc-2.95.2/lib/gcc-lib/alphaev56-dec-osf4.0d/2.95.2/mips
> -tfile -v -I alpha.warn.o~ -o alpha.warn.o alpha.warn.s
>    mips-tfile version 2.95.2 19991024 (release)
>    %
> 
> Compiling the same file with an i586-pc-linux-gnu gcc 2.95.2 and STL
> produces no warnings.
> 
> I don't know whether this is an actual alignment problem in the STL,
> or "just" a spurious warning, but either way, it seems to me that it
> qualifies as a (minor) bug: <vector> is shipped as part of a gcc
> release,
> and IMHO it should be warning-free under "reasonable" warning options
> like -Wcast-align.  (Or if the warning is genuine but harmless, perhaps
> this should be documented?)
> 
> Along with this message, I am MIME-attaching the files
> 
>    alpha.warn.cc                C++ cource code file shown above
>    alpha.warn.script            script(1) transcript shown above
>    alpha.warn.ii.bz2            cpp output from above run (compressed)
> 
> --
> -- Jonathan Thornburg <jthorn@thp.univie.ac.at>
>    http://www.thp.univie.ac.at/~jthorn/home.html
>    Universitaet Wien (Vienna, Austria) / Institut fuer Theoretische
> Physik
>    "C++ is to programming as sex is to reproduction. Better ways might
>     technically exist but they're not nearly as much fun." -- Nikolai
> Irgens
> 
>   ------------------------------------------------------------------------
> 
>    alpha.warn.ccName: alpha.warn.cc
>                 Type: C++ source code (TEXT/PLAIN)
> 
>                         Name: alpha.warn.script
>    alpha.warn.script    Type: C++ source code (TEXT/PLAIN)
>                     Encoding: quoted-printable
> 
>                         Name: alpha.warn.ii.bz2
>    alpha.warn.ii.bz2    Type: APPLICATION/x-bzip2
>                     Encoding: base64

-- 
==============================================
    Martin Sebor, Lead Software Engineer
C++ Standards Group, Rogue Wave Software, Inc.
    sebor@roguewave.com   (303) 545-3287

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