Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang warning fixes #94

Merged
merged 1 commit into from
Dec 6, 2014
Merged

Clang warning fixes #94

merged 1 commit into from
Dec 6, 2014

Conversation

emoon
Copy link
Contributor

@emoon emoon commented Dec 6, 2014

No description provided.

ocornut added a commit that referenced this pull request Dec 6, 2014
@ocornut ocornut merged commit 1236910 into ocornut:master Dec 6, 2014
@ocornut
Copy link
Owner

ocornut commented Dec 6, 2014

Thanks!

@emoon
Copy link
Contributor Author

emoon commented Dec 6, 2014

np!

I also noticed that when you build the opengl_example you get this

g++ -I/usr/local/Cellar/glew/1.10.0/include -I/usr/local/include -I../../ -c -o main.o main.cpp
main.cpp:63:79: warning: offset of on non-POD type 'ImDrawVert' [-Winvalid-offsetof]
        glVertexPointer(2, GL_FLOAT, sizeof(ImDrawVert), (void*)(vtx_buffer + offsetof(ImDrawVert, pos)));
                                                                              ^                    ~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0/include/stddef.h:87:24: note: expanded from macro 'offsetof'
#define offsetof(t, d) __builtin_offsetof(t, d)
                       ^
main.cpp:64:81: warning: offset of on non-POD type 'ImDrawVert' [-Winvalid-offsetof]
        glTexCoordPointer(2, GL_FLOAT, sizeof(ImDrawVert), (void*)(vtx_buffer + offsetof(ImDrawVert, uv)));
                                                                                ^                    ~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0/include/stddef.h:87:24: note: expanded from macro 'offsetof'
#define offsetof(t, d) __builtin_offsetof(t, d)
                       ^
main.cpp:65:86: warning: offset of on non-POD type 'ImDrawVert' [-Winvalid-offsetof]
        glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ImDrawVert), (void*)(vtx_buffer + offsetof(ImDrawVert, col)));
                                                                                     ^                    ~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0/include/stddef.h:87:24: note: expanded from macro 'offsetof'
#define offsetof(t, d) __builtin_offsetof(t, d)
                       ^
3 warnings generated.
g++ -I/usr/local/Cellar/glew/1.10.0/include -I/usr/local/include -I../../ -c -o ../../imgui.o ../../imgui.cpp
g++ -o imgui_example main.o ../../imgui.o -I/usr/local/Cellar/glew/1.10.0/include -I/usr/local/include -I../../ -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo -L/usr/local/Cellar/glew/1.10.0/lib -L/usr/local/lib -lglew -lglfw3
Build complete for Mac OS X

I wasn't sure how you want to address this so I figured I let you know instead.

@ocornut
Copy link
Owner

ocornut commented Dec 6, 2014

Arghh c++, finding new ways to get in your way. I'll add an offsetof macro.

@emoon
Copy link
Contributor Author

emoon commented Dec 6, 2014

It sure does.

@emoon
Copy link
Contributor Author

emoon commented Dec 6, 2014

Btw something that may be of interest for you is Travis-CI:

http://docs.travis-ci.com/user/languages/cpp/

It will allow you to setup so you can have builds of your project (for non-windows platforms) being compiled and report errors.

I haven't tried it myself (as I need Windows support) but might be worth considering and it seems quite simple to setup.

@benblo
Copy link

benblo commented Feb 28, 2017

I still get warnings, even with the OFFSETOF () macro ;)

g++ -I../../ -I../libs/gl3w `pkg-config --cflags glfw3` -Wall -Wformat -c -o imgui_impl_glfw_gl3.o imgui_impl_glfw_gl3.cpp
imgui_impl_glfw_gl3.cpp: In function ‘bool ImGui_ImplGlfwGL3_CreateDeviceObjects()’:
imgui_impl_glfw_gl3.cpp:260: warning: invalid access to non-static data member ‘ImDrawVert::pos’  of NULL object
imgui_impl_glfw_gl3.cpp:260: warning: (perhaps the ‘offsetof’ macro was used incorrectly)
imgui_impl_glfw_gl3.cpp:261: warning: invalid access to non-static data member ‘ImDrawVert::uv’  of NULL object
imgui_impl_glfw_gl3.cpp:261: warning: (perhaps the ‘offsetof’ macro was used incorrectly)
imgui_impl_glfw_gl3.cpp:262: warning: invalid access to non-static data member ‘ImDrawVert::col’  of NULL object
imgui_impl_glfw_gl3.cpp:262: warning: (perhaps the ‘offsetof’ macro was used incorrectly)

On Centos 6 btw.
I suppose those are harmless?

@ocornut
Copy link
Owner

ocornut commented Feb 28, 2017 via email

@benblo
Copy link

benblo commented Mar 1, 2017

No idea :) pretty new to Linux & gcc.
But your macro doesn't make use of it at all right? All I see is this voodoo:
#define OFFSETOF(TYPE, ELEMENT) ((size_t)&(((TYPE *)0)->ELEMENT))

@Keenuts
Copy link

Keenuts commented Aug 20, 2019

Hi :)

If the clang, if we use the sanitizer for undefined behaviors, the IM_OFFSETOF macro raises some errors at run-time.

A workaround could be to do this:

#if defined(__clang__)
# define IM_OFFSETOF(_TYPE, _MEMBER) offsetof(_TYPE, _MEMBER)
#else
# define IM_OFFSETOF(_TYPE,_MEMBER)  ((size_t)&(((_TYPE*)0)->_MEMBER))
#endif

Would you be OK with something like that ?

@ocornut
Copy link
Owner

ocornut commented Aug 20, 2019 via email

@Keenuts
Copy link

Keenuts commented Aug 20, 2019

yes sure, the I had the issue on both clang 6 and clang 8.0.1.

To reproduce:

  • clone the repo, branch master
  • go to examples/example_glfw_opengl3
  • edit Makefile
  • build & run
@@ 12
-#CXX = clang++
+CXX = clang++

@@ 21
-CXXFLAGS = -I../ -I../../
+CXXFLAGS = -I../ -I../../ -fsanitize=undefined -fsanitize-recover=all

@@ 30
-SOURCES += ../libs/gl3w/GL/gl3w.c
-CXXFLAGS += -I../libs/gl3w
+#SOURCES += ../libs/gl3w/GL/gl3w.c
+#CXXFLAGS += -I../libs/gl3w

-# CXXFLAGS = -lGLEW -DIMGUI_IMPL_OPENGL_LOADER_GLEW
+CXXFLAGS += -lGLEW -DIMGUI_IMPL_OPENGL_LOADER_GLEW
../imgui_impl_opengl3.cpp:216:113: runtime error: member access within null pointer of type 'ImDrawVert'
../imgui_impl_opengl3.cpp:217:113: runtime error: member access within null pointer of type 'ImDrawVert'
../imgui_impl_opengl3.cpp:218:113: runtime error: member access within null pointer of type 'ImDrawVert'

ocornut added a commit that referenced this pull request Aug 22, 2019
@ocornut
Copy link
Owner

ocornut commented Aug 22, 2019

Thank you @Keenuts. My next question was to find out in which version of Clang this appeared, but it seems to be a C++11 thing so I am now using offsetof() on all C++11 compliant compilers. All my local compiler tests seems to be passing.

@Keenuts
Copy link

Keenuts commented Aug 22, 2019

Oh cool, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants