Skip to content

Commit

Permalink
Add workaround for Clang 15 compatibility in Generator. (#374)
Browse files Browse the repository at this point in the history
* Add workaround for Clang 15 compatibility in Generator.

* Updated README recommendations for Clang 15 and removed specific workaround settings for Clang 15 from CMake configuration.
  • Loading branch information
faker2048 committed Mar 14, 2024
1 parent 83615f3 commit c7929c6
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Required Compiler: clang (>= 10.0.0) or gcc (>= 10.3) or Apple-clang (>= 14)

Note that we need to add the `-Wno-maybe-uninitialized` option when we use gcc 12 due to a false positive diagnostic message by gcc 12

Note that when using clang 15 it may be necessary to add the `-Wno-unsequenced` option, which is a false positive of clang 15. See https://github.com/llvm/llvm-project/issues/56768 for details. If you're using `async_simple::Generator`, there may be some compiler bugs in clang15. We suggest to use clang17 or higher for that.
If you're using `async_simple::Generator`, there may be some compiler bugs in clang15. We suggest to use clang17 or higher for that.

If you meet any problem about MSVC Compiler Error C4737. Try to add the /EHa option to fix the problem.

Expand Down
2 changes: 1 addition & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async\_simple 涉及 C++20 协程,对编译器版本有较高要求。需要 c

注意当使用 gcc12 时需要加上 `-Wno-maybe-uninitialized` 选项因为 gcc12 的一个误报。详情可见 https://github.com/alibaba/async_simple/issues/234。

注意当使用 clang15 时可能需要加上 `-Wno-unsequenced` 选项,这是clang15的一个误报。详情可见 https://github.com/llvm/llvm-project/issues/56768。若你需要使用 `async_simple::Generator`,我们推荐使用 clang17 或更高的版本因为在低版本 clang 上存在一些关于 Generator 的 bug report。
若你需要使用 `async_simple::Generator`,我们推荐使用 clang17 或更高的版本因为在低版本 clang 上存在一些关于 Generator 的 bug report。

注意,如果使用msvc时遇到了C4737错误,请加上选项/EHa。

Expand Down
5 changes: 5 additions & 0 deletions async_simple/coro/Generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
#ifndef ASYNC_SIMPLE_CORO_GENERATOR_H
#define ASYNC_SIMPLE_CORO_GENERATOR_H

#if defined(__clang__) && __clang_major__ == 15
// See: https://github.com/alibaba/async_simple/issues/372
#warning "Clang 15 is not supported for Generator due to some issues."
#endif

#if __has_include(<generator>)

#include <generator>
Expand Down
8 changes: 0 additions & 8 deletions async_simple/coro/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,4 @@ add_executable(async_simple_coro_test ${coro_test_src} ${PROJECT_SOURCE_DIR}/asy

target_link_libraries(async_simple_coro_test async_simple ${deplibs} ${testdeplibs})

if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND
CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "15.0" AND
CMAKE_CXX_COMPILER_VERSION VERSION_LESS "16.0")
# Clang gives incorrect warnings, See https://github.com/llvm/llvm-project/issues/56768
message("Applying -Wno-unsequenced to async_simple_coro_test for Clang 15.x")
target_compile_options(async_simple_coro_test PRIVATE -Wno-unsequenced)
endif()

add_test(NAME run_async_simple_coro_test COMMAND async_simple_coro_test)
9 changes: 9 additions & 0 deletions async_simple/coro/test/GeneratorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
* limitations under the License.
*/

#if defined(__clang__) && __clang_major__ == 15
// See: https://github.com/alibaba/async_simple/issues/372
#define SKIP_GENERATOR_TEST
#endif

#ifndef SKIP_GENERATOR_TEST

#include <algorithm>
#include <array>
#include <iostream>
Expand Down Expand Up @@ -398,3 +405,5 @@ TEST_F(GeneratorTest, testNoCopyClass) {
}

} // namespace async_simple::coro

#endif // SKIP_GENERATOR_TEST

0 comments on commit c7929c6

Please sign in to comment.