Description
Confirm by changing [ ] to [x] below to ensure that it's a bug:
- [ X] I've gone though Developer Guide and API reference
- [ X] I've searched for previous similar issues and didn't find any solution
Describe the bug
The build breaks because one variable is being set but not used. This should be just a warming but it causes the build to break since -Werror is turned on.
SDK version number
1.9.149 compiling with clang 13.0
Platform/OS/Hardware/Device
What are you running the sdk on?
Linux Ubuntu Focal 19.04
To Reproduce (observed behavior)
The only think I needed to do was to checkout the above version and try to build with cmake.
Expected behavior
I expected the build to go through.
Logs/output
/ssd/install-20211120/bin/clang++ -DAWS_MQTT_WITH_WEBSOCKETS -DAWS_SDK_VERSION_MAJOR=1 -DAWS_SDK_VERSION_MINOR=9 -DAWS_SDK_VERSION_PATCH=149 -DAWS_USE_EPOLL -DENABLE_CURL_CLIENT -DENABLE_OPENSSL_ENCRYPTION -DHAS_PATHCONF -DHAS_UMASK -DPLATFORM_LINUX -Daws_cpp_sdk_text_to_speech_EXPORTS -I/ssd/build-deps/aws-sdk-cpp-1.9.149/aws-cpp-sdk-text-to-speech/include -I/ssd/build-deps/aws-sdk-cpp-1.9.149/aws-cpp-sdk-polly/include -I/ssd/build-deps/aws-sdk-cpp-1.9.149/aws-cpp-sdk-core/include -I/ssd/build-deps/aws-sdk-cpp-1.9.149/crt/aws-crt-cpp/include -I/ssd/build-deps/aws-sdk-cpp-1.9.149/crt/aws-crt-cpp/crt/aws-c-http/include -I/ssd/build-deps/aws-sdk-cpp-1.9.149/crt/aws-crt-cpp/crt/aws-c-io/include -I/ssd/build-deps/aws-sdk-cpp-1.9.149/crt/aws-crt-cpp/crt/s2n -I/ssd/build-deps/aws-sdk-cpp-1.9.149/crt/aws-crt-cpp/crt/s2n/api -I/ssd/build-deps/aws-sdk-cpp-1.9.149/crt/aws-crt-cpp/crt/aws-c-common/include -I/ssd/build-deps/aws-sdk-cpp-1.9.149/build-tmp/crt/aws-crt-cpp/crt/aws-c-common/generated/include -I/ssd/build-deps/aws-sdk-cpp-1.9.149/crt/aws-crt-cpp/crt/aws-c-cal/include -I/ssd/build-deps/aws-sdk-cpp-1.9.149/crt/aws-crt-cpp/crt/aws-c-compression/include -I/ssd/build-deps/aws-sdk-cpp-1.9.149/crt/aws-crt-cpp/crt/aws-c-mqtt/include -I/ssd/build-deps/aws-sdk-cpp-1.9.149/crt/aws-crt-cpp/crt/aws-c-auth/include -I/ssd/build-deps/aws-sdk-cpp-1.9.149/crt/aws-crt-cpp/crt/aws-checksums/include -I/ssd/build-deps/aws-sdk-cpp-1.9.149/crt/aws-crt-cpp/crt/aws-c-event-stream/include -I/ssd/build-deps/aws-sdk-cpp-1.9.149/crt/aws-crt-cpp/crt/aws-c-s3/include -isystem /ssd/install-20211120/openssl-1.1.1l/include -Wno-error -I/ssd/install-20211120/openssl-1.1.1l/include/openssl -I/ssd/install-20211120/include -I/ssd/install-20211120/include/openssl -O3 -DNDEBUG -fPIC -fno-exceptions -std=c++11 -Wall -Werror -pedantic -Wextra -DS2N_SIKE_P434_R3_ASM -DS2N_BIKE_R3_AVX2 -DS2N_BIKE_R3_AVX512 -DS2N_BIKE_R3_PCLMUL -DS2N_BIKE_R3_VPCLMUL -DS2N_KYBER512R3_AVX2_BMI2 -DS2N_ADX -DS2N_HAVE_EXECINFO -DS2N_CPUID_AVAILABLE -fPIC -DS2N_FALL_THROUGH_SUPPORTED -DS2N___RESTRICT__SUPPORTED -pthread -MD -MT aws-cpp-sdk-text-to-speech/CMakeFiles/aws-cpp-sdk-text-to-speech.dir/source/text-to-speech/TextToSpeechManager.cpp.o -MF aws-cpp-sdk-text-to-speech/CMakeFiles/aws-cpp-sdk-text-to-speech.dir/source/text-to-speech/TextToSpeechManager.cpp.o.d -o aws-cpp-sdk-text-to-speech/CMakeFiles/aws-cpp-sdk-text-to-speech.dir/source/text-to-speech/TextToSpeechManager.cpp.o -c /ssd/build-deps/aws-sdk-cpp-1.9.149/aws-cpp-sdk-text-to-speech/source/text-to-speech/TextToSpeechManager.cpp
/ssd/build-deps/aws-sdk-cpp-1.9.149/aws-cpp-sdk-text-to-speech/source/text-to-speech/TextToSpeechManager.cpp:149:33: error: variable 'amountRead' set but not used [-Werror,-Wunused-but-set-variable]
std::streamsize amountRead(0);
^
1 error generated.
[820/1127] Building CXX object aws-cpp-sdk-access-management/CMakeFiles/aws-cpp-sdk-access-management.dir/source/AccessManagementClient.cpp.o
[821/1127] Building CXX object aws-cpp-sdk-s3-encryption/CMakeFiles/aws-cpp-sdk-s3-encryption.dir/source/s3-encryption/modules/CryptoModuleFactory.cpp.o
[822/1127] Building CXX object aws-cpp-sdk-s3-encryption/CMakeFiles/aws-cpp-sdk-s3-encryption.dir/source/s3-encryption/modules/CryptoModule.cpp.o
[823/1127] Building CXX object aws-cpp-sdk-core/CMakeFiles/aws-cpp-sdk-core.dir/ub_core.cpp.o
[824/1127] Building CXX object aws-cpp-sdk-workspaces/CMakeFiles/aws-cpp-sdk-workspaces.dir/ub_WORKSPACES.cpp.o
[825/1127] Building CXX object aws-cpp-sdk-ssm/CMakeFiles/aws-cpp-sdk-ssm.dir/ub_SSM.cpp.o
[826/1127] Building CXX object aws-cpp-sdk-ec2/CMakeFiles/aws-cpp-sdk-ec2.dir/ub_EC2.cpp.o
[827/1127] Building CXX object aws-cpp-sdk-sagemaker/CMakeFiles/aws-cpp-sdk-sagemaker.dir/ub_SAGEMAKER.cpp.o
ninja: build stopped: subcommand failed.
Additional context
The culprit is this snippet. You see that amountRead is set but never used.
std::streamsize amountRead(0);
unsigned char buffer[BUFF_SIZE];
std::lock_guard<std::mutex> m(m_driverLock);
m_activeDriver->Prime();
bool successfullyPlayed(true);
while (stream && successfullyPlayed)
{
stream.read((char*) buffer, BUFF_SIZE);
auto read = stream.gcount();
AWS_LOGSTREAM_TRACE(CLASS_TAG, "Writing " << read << " bytes to device.");
successfullyPlayed = m_activeDriver->WriteBufferToDevice(buffer, (std::size_t)read);
amountRead += read;
played = successfullyPlayed;
}
You can see that I even try to set Wno-error but the next -Werror overrides it.
[819/1127] Building CXX object aws-cpp-sdk-text-to-speech/CMakeFiles/aws-cpp-sdk-text-to-speech.dir/source/text-to-speech/TextToSpeechManager.cpp.o
FAILED: aws-cpp-sdk-text-to-speech/CMakeFiles/aws-cpp-sdk-text-to-speech.dir/source/text-to-speech/TextToSpeechManager.cpp.o
/ssd/install-20211120/bin/clang++ -DAWS_MQTT_WITH_WEBSOCKETS -DAWS_SDK_VERSION_MAJOR=1 -DAWS_SDK_VERSION_MINOR=9 -DAWS_SDK_VERSION_PATCH=149 -DAWS_USE_EPOLL -DENABLE_CURL_CLIENT -DENABLE_OPENSSL_ENCRYPTION -DHAS_PATHCONF -DHAS_UMASK -DPLATFORM_LINUX -Daws_cpp_sdk_text_to_speech_EXPORTS -I/ssd/build-deps/aws-sdk-cpp-1.9.149/aws-cpp-sdk-text-to-speech/include -I/ssd/build-deps/aws-sdk-cpp-1.9.149/aws-cpp-sdk-polly/include -I/ssd/build-deps/aws-sdk-cpp-1.9.149/aws-cpp-sdk-core/include -I/ssd/build-deps/aws-sdk-cpp-1.9.149/crt/aws-crt-cpp/include -I/ssd/build-deps/aws-sdk-cpp-1.9.149/crt/aws-crt-cpp/crt/aws-c-http/include -I/ssd/build-deps/aws-sdk-cpp-1.9.149/crt/aws-crt-cpp/crt/aws-c-io/include -I/ssd/build-deps/aws-sdk-cpp-1.9.149/crt/aws-crt-cpp/crt/s2n -I/ssd/build-deps/aws-sdk-cpp-1.9.149/crt/aws-crt-cpp/crt/s2n/api -I/ssd/build-deps/aws-sdk-cpp-1.9.149/crt/aws-crt-cpp/crt/aws-c-common/include -I/ssd/build-deps/aws-sdk-cpp-1.9.149/build-tmp/crt/aws-crt-cpp/crt/aws-c-common/generated/include -I/ssd/build-deps/aws-sdk-cpp-1.9.149/crt/aws-crt-cpp/crt/aws-c-cal/include -I/ssd/build-deps/aws-sdk-cpp-1.9.149/crt/aws-crt-cpp/crt/aws-c-compression/include -I/ssd/build-deps/aws-sdk-cpp-1.9.149/crt/aws-crt-cpp/crt/aws-c-mqtt/include -I/ssd/build-deps/aws-sdk-cpp-1.9.149/crt/aws-crt-cpp/crt/aws-c-auth/include -I/ssd/build-deps/aws-sdk-cpp-1.9.149/crt/aws-crt-cpp/crt/aws-checksums/include -I/ssd/build-deps/aws-sdk-cpp-1.9.149/crt/aws-crt-cpp/crt/aws-c-event-stream/include -I/ssd/build-deps/aws-sdk-cpp-1.9.149/crt/aws-crt-cpp/crt/aws-c-s3/include -isystem /ssd/install-20211120/openssl-1.1.1l/include -Wno-error -I/ssd/install-20211120/openssl-1.1.1l/include/openssl -I/ssd/install-20211120/include -I/ssd/install-20211120/include/openssl -O3 -DNDEBUG -fPIC -fno-exceptions -std=c++11 -Wall -Werror -pedantic -Wextra -DS2N_SIKE_P434_R3_ASM -DS2N_BIKE_R3_AVX2 -DS2N_BIKE_R3_AVX512 -DS2N_BIKE_R3_PCLMUL -DS2N_BIKE_R3_VPCLMUL -DS2N_KYBER512R3_AVX2_BMI2 -DS2N_ADX -DS2N_HAVE_EXECINFO -DS2N_CPUID_AVAILABLE -fPIC -DS2N_FALL_THROUGH_SUPPORTED -DS2N___RESTRICT__SUPPORTED -pthread -MD -MT aws-cpp-sdk-text-to-speech/CMakeFiles/aws-cpp-sdk-text-to-speech.dir/source/text-to-speech/TextToSpeechManager.cpp.o -MF aws-cpp-sdk-text-to-speech/CMakeFiles/aws-cpp-sdk-text-to-speech.dir/source/text-to-speech/TextToSpeechManager.cpp.o.d -o aws-cpp-sdk-text-to-speech/CMakeFiles/aws-cpp-sdk-text-to-speech.dir/source/text-to-speech/TextToSpeechManager.cpp.o -c /ssd/build-deps/aws-sdk-cpp-1.9.149/aws-cpp-sdk-text-to-speech/source/text-to-speech/TextToSpeechManager.cpp
I can see Werror being set on aws-sdk-cpp-1.9.149/cmake/compiler_settings.cmake
macro(set_gcc_warnings)
list(APPEND AWS_COMPILER_WARNINGS "-Wall" "-Werror" "-pedantic" "-Wextra")
if(COMPILER_CLANG)
if(PLATFORM_ANDROID)
# when using clang with libc and API lower than 21 we need to include Android support headers and ignore the gnu-include-next warning.
if(ANDROID_STL MATCHES "libc" AND ANDROID_NATIVE_API_LEVEL_NUM LESS "21")
# NDK lower than 12 doesn't support ignoring the gnu-include-next warning so we need to disable pedantic mode.
if(NDK_RELEASE_NUMBER LESS "12000")
string(REGEX REPLACE "-pedantic" "" AWS_COMPILER_WARNINGS "${AWS_COMPILER_WARNINGS}")
else()
list(APPEND AWS_COMPILER_WARNINGS "-Wno-gnu-include-next")
endif()
endif()
endif()
endif()
endmacro()