[ https://issues.apache.org/jira/browse/PROTON-2714?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17714605#comment-17714605 ]
ASF GitHub Bot commented on PROTON-2714: ---------------------------------------- jiridanek commented on code in PR #397: URL: https://github.com/apache/qpid-proton/pull/397#discussion_r1172624502 ########## c/include/proton/annotations.h: ########## @@ -0,0 +1,93 @@ +#ifndef PROTON_ANNOTATIONS_H +#define PROTON_ANNOTATIONS_H 1 + +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @cond INTERNAL + * + * Compiler specific mechanisms for annotating functions and function parameters. + * + * SAL (MSVC) documentation: + * https://learn.microsoft.com/en-us/cpp/c-runtime-library/sal-annotations?view=msvc-170 + * https://learn.microsoft.com/en-us/cpp/code-quality/understanding-sal?view=msvc-170&viewFallbackFrom=vs-2019 + * https://learn.microsoft.com/en-us/cpp/code-quality/annotating-function-parameters-and-return-values?view=msvc-170 + * GCC documentation: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html + * Clang documentation: https://clang.llvm.org/docs/AttributeReference.html + * Clang Analyzer documentation: https://clang-analyzer.llvm.org/annotations.html + * + * Example usage for the implemented annotation macros: + * + * std::string stringPrintf(PN_PRINTF_FORMAT const char* format, ...) + * PN_PRINTF_FORMAT_ATTR(1, 2); + * + * PN_NODISCARD std::unique_lock<Mutex> make_unique_lock( + * Mutex& mutex, Args&&... args) { ... } + * + */ + +// compiler specific attribute translation +// msvc should come first, so if clang is in msvc mode it gets the right defines + +// warn format placeholders + +// NOTE: this will only do checking in msvc with versions that support /analyze +#ifdef _MSC_VER + + #include <stddef.h> + + #ifdef _USE_ATTRIBUTES_FOR_SAL + #undef _USE_ATTRIBUTES_FOR_SAL + #endif + + #define _USE_ATTRIBUTES_FOR_SAL 1 + #include <sal.h> Review Comment: no idea what this is there for, but facebook thought it worthy of including, so I copied it over > logger.c:204:41: error: format ‘%x’ expects argument of type ‘unsigned int’, > but argument 4 has type ‘size_t’ {aka ‘long unsigned int’} [-Werror=format=] > --------------------------------------------------------------------------------------------------------------------------------------------------------- > > Key: PROTON-2714 > URL: https://issues.apache.org/jira/browse/PROTON-2714 > Project: Qpid Proton > Issue Type: Bug > Components: proton-c > Affects Versions: proton-c-0.38.0 > Reporter: Jiri Daněk > Assignee: Jiri Daněk > Priority: Minor > > These don't actually produce compiler diagnostics, that only appears after > the printing functions are annotated. So this is not causing compilation > failures currently. > {noformat} > /home/jdanek/repos/qpid/qpid-proton/c/src/ssl/openssl.c: In function > ‘process_input_ssl’: > /home/jdanek/repos/qpid/qpid-proton/c/src/ssl/openssl.c:1039:70: error: > format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘size_t’ > {aka ‘long unsigned int’} [-Werror=format=] > 1039 | ssl_log( transport, PN_LEVEL_TRACE, "process_input_ssl( data > size=%d )",available ); > | > ~^ ~~~~~~~~~ > | > | | > | > int size_t {aka long unsigned int} > | > %ld > cc1: all warnings being treated as errors > gmake[2]: *** [c/CMakeFiles/qpid-proton-core-static.dir/build.make:520: > c/CMakeFiles/qpid-proton-core-static.dir/src/ssl/openssl.c.o] Error 1 > gmake[1]: *** [CMakeFiles/Makefile2:1375: > c/CMakeFiles/qpid-proton-core-static.dir/all] Error 2 > gmake: *** [Makefile:146: all] Error 2 > {noformat} > {noformat} > /home/jdanek/repos/qpid/qpid-proton/c/src/core/logger.c: In function > ‘pni_logger_log_raw’: > /home/jdanek/repos/qpid/qpid-proton/c/src/core/logger.c:204:41: error: format > ‘%x’ expects argument of type ‘unsigned int’, but argument 4 has type > ‘size_t’ {aka ‘long unsigned int’} [-Werror=format=] > 204 | pn_fixed_string_addf(&out, "%04x/%04x: ", i, size); > | ~~~^ ~~~~ > | | | > | | size_t {aka long > unsigned int} > | unsigned int > | %04lx > cc1: all warnings being treated as errors > {noformat} -- This message was sent by Atlassian Jira (v8.20.10#820010) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@qpid.apache.org For additional commands, e-mail: dev-h...@qpid.apache.org