Author Topic: Strange warnings when compiling CVS...  (Read 13906 times)

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Strange warnings when compiling CVS...
« on: November 21, 2005, 02:59:10 am »
Code
sdk\as\bindings\scriptbindings.cpp: In function `void Register_ProjectFile(asIScriptEngine*)':
sdk\as\bindings\scriptbindings.cpp:262: warning: invalid access to non-static data member `ProjectFile::project' of NULL object
sdk\as\bindings\scriptbindings.cpp:262: warning: (perhaps the `offsetof' macro was used incorrectly)

This goes from lines 262 to 270 of the same file.

Code
In file included from plugins\astyle\/formattersettings.h:4,
                 from plugins\astyle\formattersettings.cpp:2:
plugins\astyle\/./astyle/astyle.h:68:2: warning: #warning Compiling DEBUG version (which will print lots of TRACE information to cerr)!

How to get rid of these? And I mean "fix", not just "hide" :P


sethjackson

  • Guest
Re: Strange warnings when compiling CVS...
« Reply #1 on: November 21, 2005, 03:04:30 am »
It seems that ProjectFile::project is NULL???

I looked at the source file and I don't get what it is doing. LOL

All the stuff in quotes...... I guess I'm dumb or something.

Also does the forward slash have anything to do with it?

And is it compiling debug version or something??? I haven't compiled from CVS in awhile so I'm sorta lost. :)
« Last Edit: November 21, 2005, 03:12:22 am by Seth Jackson »

Offline Urxae

  • Regular
  • ***
  • Posts: 376
Re: Strange warnings when compiling CVS...
« Reply #2 on: November 21, 2005, 03:27:25 am »
I looked into this when I first saw those warnings, and the offsetof macro is indeed used incorrectly. It should only be used on POD types, and ProjectFile doesn't qualify.
Wouldn't know how to actually fix this, other than rewrite that part of the AngelScript engine to use member data pointers. That might require some template magic akin to boost::function to work for multiple types though, unless you only need it to work for ProjectFile.

It seems that ProjectFile::project is NULL???
No, it uses the offsetof macro, which basically casts a pointer to a member of a dereferenced null pointer to an unsigned integer to get the member's offset into the structure.

Quote
And is it compiling debug version or something??? I haven't compiled from CVS in awhile so I'm sorta lost. :)
This is a fairly recent addition to CVS (at least, to the HEAD branch).

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: Strange warnings when compiling CVS...
« Reply #3 on: November 21, 2005, 04:45:45 am »
I read more about it.

-Wno-invalid-offsetof (C++ only)
    Suppress warnings from applying the offsetof macro to a non-POD type. According to the 1998 ISO C++ standard, applying offsetof to a non-POD type is undefined. In existing C++ implementations, however, offsetof typically gives meaningful results even when applied to certain kinds of non-POD types. (Such as a simple struct that fails to be a POD type only by virtue of having a constructor.) This flag is for users who are aware that they are writing nonportable code and who have deliberately chosen to ignore the warning about it.

I modified the codeblocks-NewBuild.cbp to include this flag, but I'd like to know if I can commit. It might throw errors using other compilers.

Also, I added a definition of NDEBUG inside the astyle.h file, to rebuild the astyle plugin ito release mode.

Yiannis, is it ok to commit?

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Strange warnings when compiling CVS...
« Reply #4 on: November 21, 2005, 08:39:50 am »
Rick, this flag works only for GCC-4.0 and up. Don't commit it...
Be patient!
This bug will be fixed soon...

Offline Urxae

  • Regular
  • ***
  • Posts: 376
Re: Strange warnings when compiling CVS...
« Reply #5 on: November 21, 2005, 12:21:18 pm »
I modified the codeblocks-NewBuild.cbp to include this flag, but I'd like to know if I can commit. It might throw errors using other compilers.

I thought you wanted to
Quote
"fix", not just "hide"
this? :p

Rick, this flag works only for GCC-4.0 and up. Don't commit it...

According to this gcc mailing list post it would be added in 3.4. And I can confirm it's available in mingw 3.4.2:
Code
D:\Temp> cat test.cpp
#include <cstdio>

struct data
{
    data() : x(0) {}
    int x;
};

int main()
{
    std::printf("hello world\n");
    std::printf("offsetof x: %i\n", offsetof(data, x));
}

D:\Temp> g++ test.cpp -o test.exe
test.cpp: In function `int main()':
test.cpp:12: warning: invalid access to non-static data member `data::x' of NULL object
test.cpp:12: warning: (perhaps the `offsetof' macro was used incorrectly)

D:\Temp> g++ -Wno-invalid-offsetoff test.cpp -o test.exe

D:\Temp> test
hello world
offsetof x: 0

D:\Temp> g++ --version
g++ (GCC) 3.4.2 (mingw-special)
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Strange warnings when compiling CVS...
« Reply #6 on: November 21, 2005, 12:56:02 pm »
Quote from: Urxae
According to this gcc mailing list post it would be added in 3.4. And I can confirm it's available in mingw 3.4.2:

Thanks for the correction, but it still doesn't matter. There's no rule to require a specific gcc version to build C::B. In other words, it still can't go in the project file as an option.
Many users (esp. linux users) use older versions like gcc 3.3.5...
Be patient!
This bug will be fixed soon...

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Strange warnings when compiling CVS...
« Reply #7 on: November 21, 2005, 01:19:53 pm »
It actually works fine under certain conditions, but there are caveats.

First, it works with C++ files, but not with C files. This is an issue when setting it for the Code::Blocks project, but you would not want to do that anyway.

You will want to set it for the smallest possible subset, which is the SDK target in this case.
This, however, means that the major part of Code::Blocks (over 400 files) is compiled without this warning, which is bad. If the build system allowed us to pass custom compiler flags to individual files, that might be acceptable, but compiling the whole SDK this way is dangerous - it may hide actual errors in other places.

Lastly and most importantly, when using older compiler versions, you would expect it to produce additional warnings about unknown command line options in addition to the existing ones.
However, reality is still worse. gcc will actually bail out with an error, so the build is broken.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: Strange warnings when compiling CVS...
« Reply #8 on: November 21, 2005, 04:47:21 pm »
Alright then :) Oh, about the Astyle plugin, that I can commit, right?

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Strange warnings when compiling CVS...
« Reply #9 on: November 21, 2005, 06:25:44 pm »
Alright then :) Oh, about the Astyle plugin, that I can commit, right?

Sure :)
Be patient!
This bug will be fixed soon...

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Strange warnings when compiling CVS...
« Reply #10 on: December 15, 2005, 11:49:44 am »
I fixed it :lol: :lol: :lol:

Actually it is pretty obvious what you have to do, read the error message :)

Code
#undef offsetof
#define offsetof(T, M) ( reinterpret_cast <size_t> ( & reinterpret_cast <const volatile char &>(reinterpret_cast<T *> (1000)->M) ) - 1000u)

Now say again that macros are not evil  8)
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Strange warnings when compiling CVS...
« Reply #11 on: December 15, 2005, 12:25:56 pm »
Seriously now... I know it is a hack and a macro on top.

But offsetof is a hack anyway (and a macro too).

With the casts added to wxScintilla (r1512), I can compile Code::Blocks with zero warnings when putting this offsetof replacement into scriptbindings.cpp (I hope it is really a 100% valid replacement, but I think so... at least it does not crash me). Yes, zero warnings. Repeat that.
This means that any real warnings are now a lot easier to spot.

Shouldn't we go for that workaround then? We know these warnings are not related to a bug, so they are utterly useless. And the macro won't affect any other files if it is located in the cpp file.

After all, why do we compile with -Wall if we get so many useless warnings that we don't see the real ones anyway ;)
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline Michael

  • Lives here!
  • ****
  • Posts: 1608
Re: Strange warnings when compiling CVS...
« Reply #12 on: December 15, 2005, 12:38:38 pm »
I fixed it :lol: :lol: :lol:

Actually it is pretty obvious what you have to do, read the error message :)

Code
#undef offsetof
#define offsetof(T, M) ( reinterpret_cast <size_t> ( & reinterpret_cast <const volatile char &>(reinterpret_cast<T *> (1000)->M) ) - 1000u)

Now say again that macros are not evilĀ  8)

Could not be used instead of a macro an inline function?

Michael

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Strange warnings when compiling CVS...
« Reply #13 on: December 15, 2005, 01:12:23 pm »
No.

EDIT:

Slightly longer answer:
Technically, yes, but
- it is a lot more complicated
- you may have to create a temporary object (I am not sure if you can trick the compiler to do it on a pointer)
- you still must #undef offsetof, so you use preprocessor commands either way
- you need a different calling convention, meaning you have to rewrite the existing code
- you have additional constraints that offsetof has not (so it may not always work)
- it is still a hack
« Last Edit: December 15, 2005, 01:37:23 pm by thomas »
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline tiwag

  • Developer
  • Lives here!
  • *****
  • Posts: 1196
  • sailing away ...
    • tiwag.cb
Re: Strange warnings when compiling CVS...
« Reply #14 on: December 16, 2005, 01:22:27 pm »
@thomas
now i get the 20 warnings from offsetof in scriptbindings.cpp again,
but i think i'm not dreaming that your changed offsetof macro definition was already in SVN ? right?

now it isn't anymore in SVN ? why ?