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: macro expansion producing 'defined' has undefined behavior #2042

Closed
nereocystis opened this issue Oct 29, 2017 · 0 comments
Closed

Comments

@nereocystis
Copy link
Contributor

Your Environment

  • Operating System and version: Ubuntu 17.10

  • Compiler: clang version 4.0.1-6 (tags/RELEASE_401/final)
    Target: x86_64-pc-linux-gnu
    Thread model: posix
    InstalledDir: /usr/bin

  • PCL Version: HEAD

I used the following cmake command:

Expected Behavior

No warning for below line, when compiling

Current Behavior

clang warnings point out a problem with io/src/lzf.cpp, used "defined"
as part of a macro expension has undefined results.

                   ^

/home/kevin/src/pcl/io/src/lzf.cpp:58:6: error: macro expansion producing
'defined' has undefined behavior [-Werror,-Wexpansion-to-defined]
/home/kevin/src/pcl/io/src/lzf.cpp:57:43: note: expanded from macro
'STRICT_ALIGN'
#define STRICT_ALIGN !(defined(__i386) || defined (__amd64))
^
/home/kevin/src/pcl/io/src/lzf.cpp:137:5: error: macro expansion producing
'defined' has undefined behavior [-Werror,-Wexpansion-to-defined]
#if STRICT_ALIGN
^
/home/kevin/src/pcl/io/src/lzf.cpp:57:24: note: expanded from macro
'STRICT_ALIGN'
#define STRICT_ALIGN !(defined(__i386) || defined (__amd64))
^
/home/kevin/src/pcl/io/src/lzf.cpp:137:5: error: macro expansion producing
'defined' has undefined behavior [-Werror,-Wexpansion-to-defined]
/home/kevin/src/pcl/io/src/lzf.cpp:57:43: note: expanded from macro
'STRICT_ALIGN'
#define STRICT_ALIGN !(defined(__i386) || defined (__amd64))
^
4 errors generated.

Possible Solution

Fix is easy.
#define should be rewritten. I will soon submit a pull request.

Code to Reproduce

cmake .. -DCMAKE_CXX_COMPILER:FILEPATH=/usr/bin/clang++ -DCMAKE_C_COMPILER:FILEPATH=/usr/bin/clang -DCMAKE_CXX_FLAGS:STRING="-fno-omit-frame-pointer -Wno-overloaded-virtual -Wno-bind-to-temporary-copy -Wno-unused -Wno-conversion -Werror -Wno-error=dynamic-class-memaccess" -DCMAKE_C_FLAGS:STRING="-fno-omit-frame-pointer -Wno-overloaded-virtual -Wno-bind-to-temporary-copy -Wno-unused -Wno-conversion -Werror -Wno-error=dynamic-class-memaccess" -DBUILD_global_tests=ON

make

Context

Different compilers will produce inconsistent results with lzf.cpp

nereocystis added a commit to nereocystis/pcl that referenced this issue Oct 30, 2017
Modify STRICT_ALIGN because macro expansion producing 'defined' has
undefined behavior.

closes PointCloudLibrary#2042

Signed-off-by: Kevin Dalley <kevin@kelphead.org>
UnaNancyOwen pushed a commit to UnaNancyOwen/pcl that referenced this issue Nov 24, 2017
Modify STRICT_ALIGN because macro expansion producing 'defined' has
undefined behavior.

closes PointCloudLibrary#2042

Signed-off-by: Kevin Dalley <kevin@kelphead.org>
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

No branches or pull requests

1 participant