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

[C++] Fix GCC compilation failure caused by warning macro #14402

Merged

Conversation

BewareMyPower
Copy link
Contributor

Motivation

When I tried to build the C++ client with GCC 7.3 and when warnings are
printed (because BOOST_ARCH_X86_64 is not defined), the compilation
failed with:

#warning “BOOST_ARCH_X86_64 is not defined, CRC32C SSE4.2 will be disabled”
  ^~~~~~~
cc1plus: error: unrecognized command line option '-Wno-stringop-truncation' [-Werror]
cc1plus: all warnings being treated as errors

It seems to be a bug before GCC 8.1. I added
-DCMAKE_VERBOSE_MAKEFILE=ON to CMake command and see the full compile
command:

-Wno-error -Wall -Wformat-security -Wvla -Werror -Wno-sign-compare -Wno-deprecated-declarations -Wno-error=cpp -Wno-stringop-truncation

See

elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9))
add_compile_options(-Wno-stringop-truncation)

For GCC > 4.9, -Wno-stringop-truncation option was added. However,
when a message was printed by #warning macro, it would fail with the
strange error message.

The simplest way to reproduce the bug is compiling following code:

#warnings "hello"

int main() {}

You can paste the code above to https://godbolt.org/, select any GCC
compiler whose version is lower than 8.0, then add the following
options:

-Werror -Wno-error=cpp -Wno-stringop-truncation

The compilation failed for x86-64 gcc 7.5 while it succeeded for 8.1.

Modifications

Only add the -Wno-stringop-truncation option for GCC >= 8.1.

### Motivation

When I tried to build the C++ client with GCC 7.3 and when warnings are
printed (because `BOOST_ARCH_X86_64` is not defined), the compilation
failed with:

```
#warning “BOOST_ARCH_X86_64 is not defined, CRC32C SSE4.2 will be disabled”
  ^~~~~~~
cc1plus: error: unrecognized command line option '-Wno-stringop-truncation' [-Werror]
cc1plus: all warnings being treated as errors
```

It seems to be a bug before GCC 8.1. I added
`-DCMAKE_VERBOSE_MAKEFILE=ON` to CMake command and see the full compile
command:

```
-Wno-error -Wall -Wformat-security -Wvla -Werror -Wno-sign-compare -Wno-deprecated-declarations -Wno-error=cpp -Wno-stringop-truncation
```

See
https://github.com/apache/pulsar/blob/b829a4ce121268f55748bbdd6f19ac36129e7dab/pulsar-client-cpp/CMakeLists.txt#L105-L106

For GCC > 4.9, `-Wno-stringop-truncation` option was added. However,
when a message was printed by `#warning` macro, it would fail with the
strange error message.

The simplest way to reproduce the bug is compiling following code:

```c++
#warnings "hello"

int main() {}
```

You can paste the code above to https://godbolt.org/, select any GCC
compiler whose version is lower than 8.0, then add the following
options:

```
-Werror -Wno-error=cpp -Wno-stringop-truncation
```

The compilation failed for x86-64 gcc 7.5 while it succeeded for 8.1.

### Modifications

Only add the `-Wno-stringop-truncation` option for GCC >= 8.1.
@BewareMyPower
Copy link
Contributor Author

Here are the comparison for GCC 8.1 and 7.5

image

image

@BewareMyPower
Copy link
Contributor Author

Without the #warning macro, even GCC 7.5 works well. So I suspect it's a bug of GCC < 8.

image

@merlimat merlimat added this to the 2.11.0 milestone Feb 22, 2022
@merlimat merlimat merged commit 958fc78 into apache:master Feb 22, 2022
michaeljmarshall pushed a commit that referenced this pull request Feb 24, 2022
### Motivation

When I tried to build the C++ client with GCC 7.3 and when warnings are
printed (because `BOOST_ARCH_X86_64` is not defined), the compilation
failed with:

```
#warning “BOOST_ARCH_X86_64 is not defined, CRC32C SSE4.2 will be disabled”
  ^~~~~~~
cc1plus: error: unrecognized command line option '-Wno-stringop-truncation' [-Werror]
cc1plus: all warnings being treated as errors
```

It seems to be a bug before GCC 8.1. I added
`-DCMAKE_VERBOSE_MAKEFILE=ON` to CMake command and see the full compile
command:

```
-Wno-error -Wall -Wformat-security -Wvla -Werror -Wno-sign-compare -Wno-deprecated-declarations -Wno-error=cpp -Wno-stringop-truncation
```

See
https://github.com/apache/pulsar/blob/b829a4ce121268f55748bbdd6f19ac36129e7dab/pulsar-client-cpp/CMakeLists.txt#L105-L106

For GCC > 4.9, `-Wno-stringop-truncation` option was added. However,
when a message was printed by `#warning` macro, it would fail with the
strange error message.

The simplest way to reproduce the bug is compiling following code:

```c++
#warnings "hello"

int main() {}
```

You can paste the code above to https://godbolt.org/, select any GCC
compiler whose version is lower than 8.0, then add the following
options:

```
-Werror -Wno-error=cpp -Wno-stringop-truncation
```

The compilation failed for x86-64 gcc 7.5 while it succeeded for 8.1.

### Modifications

Only add the `-Wno-stringop-truncation` option for GCC >= 8.1.

(cherry picked from commit 958fc78)
@michaeljmarshall michaeljmarshall added the cherry-picked/branch-2.8 Archived: 2.8 is end of life label Feb 24, 2022
@codelipenghui codelipenghui modified the milestones: 2.11.0, 2.10.0 Feb 25, 2022
codelipenghui pushed a commit that referenced this pull request Feb 25, 2022
### Motivation

When I tried to build the C++ client with GCC 7.3 and when warnings are
printed (because `BOOST_ARCH_X86_64` is not defined), the compilation
failed with:

```
#warning “BOOST_ARCH_X86_64 is not defined, CRC32C SSE4.2 will be disabled”
  ^~~~~~~
cc1plus: error: unrecognized command line option '-Wno-stringop-truncation' [-Werror]
cc1plus: all warnings being treated as errors
```

It seems to be a bug before GCC 8.1. I added
`-DCMAKE_VERBOSE_MAKEFILE=ON` to CMake command and see the full compile
command:

```
-Wno-error -Wall -Wformat-security -Wvla -Werror -Wno-sign-compare -Wno-deprecated-declarations -Wno-error=cpp -Wno-stringop-truncation
```

See
https://github.com/apache/pulsar/blob/b829a4ce121268f55748bbdd6f19ac36129e7dab/pulsar-client-cpp/CMakeLists.txt#L105-L106

For GCC > 4.9, `-Wno-stringop-truncation` option was added. However,
when a message was printed by `#warning` macro, it would fail with the
strange error message.

The simplest way to reproduce the bug is compiling following code:

```c++
#warnings "hello"

int main() {}
```

You can paste the code above to https://godbolt.org/, select any GCC
compiler whose version is lower than 8.0, then add the following
options:

```
-Werror -Wno-error=cpp -Wno-stringop-truncation
```

The compilation failed for x86-64 gcc 7.5 while it succeeded for 8.1.

### Modifications

Only add the `-Wno-stringop-truncation` option for GCC >= 8.1.

(cherry picked from commit 958fc78)
nicoloboschi pushed a commit to nicoloboschi/pulsar that referenced this pull request Mar 1, 2022
### Motivation

When I tried to build the C++ client with GCC 7.3 and when warnings are
printed (because `BOOST_ARCH_X86_64` is not defined), the compilation
failed with:

```
#warning “BOOST_ARCH_X86_64 is not defined, CRC32C SSE4.2 will be disabled”
  ^~~~~~~
cc1plus: error: unrecognized command line option '-Wno-stringop-truncation' [-Werror]
cc1plus: all warnings being treated as errors
```

It seems to be a bug before GCC 8.1. I added
`-DCMAKE_VERBOSE_MAKEFILE=ON` to CMake command and see the full compile
command:

```
-Wno-error -Wall -Wformat-security -Wvla -Werror -Wno-sign-compare -Wno-deprecated-declarations -Wno-error=cpp -Wno-stringop-truncation
```

See
https://github.com/apache/pulsar/blob/b829a4ce121268f55748bbdd6f19ac36129e7dab/pulsar-client-cpp/CMakeLists.txt#L105-L106

For GCC > 4.9, `-Wno-stringop-truncation` option was added. However,
when a message was printed by `#warning` macro, it would fail with the
strange error message.

The simplest way to reproduce the bug is compiling following code:

```c++
#warnings "hello"

int main() {}
```

You can paste the code above to https://godbolt.org/, select any GCC
compiler whose version is lower than 8.0, then add the following
options:

```
-Werror -Wno-error=cpp -Wno-stringop-truncation
```

The compilation failed for x86-64 gcc 7.5 while it succeeded for 8.1.

### Modifications

Only add the `-Wno-stringop-truncation` option for GCC >= 8.1.
gaoran10 pushed a commit that referenced this pull request Mar 1, 2022
### Motivation

When I tried to build the C++ client with GCC 7.3 and when warnings are
printed (because `BOOST_ARCH_X86_64` is not defined), the compilation
failed with:

```
#warning “BOOST_ARCH_X86_64 is not defined, CRC32C SSE4.2 will be disabled”
  ^~~~~~~
cc1plus: error: unrecognized command line option '-Wno-stringop-truncation' [-Werror]
cc1plus: all warnings being treated as errors
```

It seems to be a bug before GCC 8.1. I added
`-DCMAKE_VERBOSE_MAKEFILE=ON` to CMake command and see the full compile
command:

```
-Wno-error -Wall -Wformat-security -Wvla -Werror -Wno-sign-compare -Wno-deprecated-declarations -Wno-error=cpp -Wno-stringop-truncation
```

See
https://github.com/apache/pulsar/blob/b829a4ce121268f55748bbdd6f19ac36129e7dab/pulsar-client-cpp/CMakeLists.txt#L105-L106

For GCC > 4.9, `-Wno-stringop-truncation` option was added. However,
when a message was printed by `#warning` macro, it would fail with the
strange error message.

The simplest way to reproduce the bug is compiling following code:

```c++
#warnings "hello"

int main() {}
```

You can paste the code above to https://godbolt.org/, select any GCC
compiler whose version is lower than 8.0, then add the following
options:

```
-Werror -Wno-error=cpp -Wno-stringop-truncation
```

The compilation failed for x86-64 gcc 7.5 while it succeeded for 8.1.

### Modifications

Only add the `-Wno-stringop-truncation` option for GCC >= 8.1.

(cherry picked from commit 958fc78)
@gaoran10 gaoran10 added the cherry-picked/branch-2.9 Archived: 2.9 is end of life label Mar 2, 2022
@BewareMyPower BewareMyPower deleted the bewaremypower/cpp-gcc-version-error branch March 11, 2022 02:25
Nicklee007 pushed a commit to Nicklee007/pulsar that referenced this pull request Apr 20, 2022
### Motivation

When I tried to build the C++ client with GCC 7.3 and when warnings are
printed (because `BOOST_ARCH_X86_64` is not defined), the compilation
failed with:

```
#warning “BOOST_ARCH_X86_64 is not defined, CRC32C SSE4.2 will be disabled”
  ^~~~~~~
cc1plus: error: unrecognized command line option '-Wno-stringop-truncation' [-Werror]
cc1plus: all warnings being treated as errors
```

It seems to be a bug before GCC 8.1. I added
`-DCMAKE_VERBOSE_MAKEFILE=ON` to CMake command and see the full compile
command:

```
-Wno-error -Wall -Wformat-security -Wvla -Werror -Wno-sign-compare -Wno-deprecated-declarations -Wno-error=cpp -Wno-stringop-truncation
```

See
https://github.com/apache/pulsar/blob/b829a4ce121268f55748bbdd6f19ac36129e7dab/pulsar-client-cpp/CMakeLists.txt#L105-L106

For GCC > 4.9, `-Wno-stringop-truncation` option was added. However,
when a message was printed by `#warning` macro, it would fail with the
strange error message.

The simplest way to reproduce the bug is compiling following code:

```c++
#warnings "hello"

int main() {}
```

You can paste the code above to https://godbolt.org/, select any GCC
compiler whose version is lower than 8.0, then add the following
options:

```
-Werror -Wno-error=cpp -Wno-stringop-truncation
```

The compilation failed for x86-64 gcc 7.5 while it succeeded for 8.1.

### Modifications

Only add the `-Wno-stringop-truncation` option for GCC >= 8.1.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/build cherry-picked/branch-2.8 Archived: 2.8 is end of life cherry-picked/branch-2.9 Archived: 2.9 is end of life doc-not-needed Your PR changes do not impact docs release/2.8.3 release/2.9.2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants