Closed Drevanoorschot closed 1 year ago
Technically assert
is a macro and not a keyword. http://go/cppref/cpp/error/assert
This means we have two approaches we could use to solve this.
1) treat it like other macros that have frequent collisions (https://cs.github.com/protocolbuffers/protobuf/blob/cffde99fc6195ca108f320c16a6ded41c42a3317/src/google/protobuf/port_def.inc?q=path%3Aport_def.inc#L950-L953) 2) treat it as a keyword (https://cs.github.com/protocolbuffers/protobuf/blob/cffde99fc6195ca108f320c16a6ded41c42a3317/src/google/protobuf/compiler/cpp/helpers.cc?q=path%3Acpp%2Fhelpers.cc#L89)
I don't particularly love either option. (1) feels more principled, but users will have a hard time accessing such fields.
Just out of curiosity, what makes the assert
macro different from the other macros that are being undefined? (https://cs.github.com/protocolbuffers/protobuf/blob/cffde99fc6195ca108f320c16a6ded41c42a3317/src/google/protobuf/port_def.inc?q=path%3Aport_def.inc#L950-L953)
As in, what makes it more troublesome to undefine assert
as opposed to the min
and max
example?
We actually talked about whether to handle it like a macro or a keyword in the team chat. We ended up deciding on keyword because the assert
macro is pulled into a great many headers transitively. min
and max
on the other hand are only defined as macros on windows, so the magnitude of their scope is significantly smaller.
What version of protobuf and what language are you using? Version: main/v22.0 Language: C++
What operating system (Linux, Windows, ...) and version? Debian GNU/Linux 11 (bullseye) x86_64
What runtime / compiler are you using (e.g., python version or gcc version) gcc (Debian 10.2.1-6) 10.2.1 20210110 cmake version 3.23.2 ninja version 1.10.2 clion 2022.2.4
What did you do? Steps to reproduce the behavior:
set(CMAKE_CXX_STANDARD 20)
find_package(Protobuf REQUIRED PATHS /usr/local/lib/cmake/protobuf)
add_library(proto-objects OBJECT "proto/COL/col.proto")
target_link_libraries(proto-objects PUBLIC protobuf::libprotobuf)
set(PROTO_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated")
target_include_directories(proto-objects PUBLIC "$<BUILD_INTERFACE:${PROTO_BINARY_DIR}>")
protobuf_generate( TARGET proto-objects IMPORT_DIRS "proto" PROTOC_OUT_DIR "${PROTO_BINARY_DIR}")
set(SOURCE_FILES tools/VcLLVM/VcLLVM.cpp) add_executable(VcLLVM ${SOURCE_FILES}) target_link_libraries(VcLLVM proto-objects)
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=ninja -G Ninja -S VcLLVM -B _build
cmake --build _build --target VcLLVM -j 9
What did you expect to see The following output:
What did you see instead? The following output:
Anything else we should know about your project / environment It is worth noting that when i change the proto variable
assert
to_assert
the project compiles just fine. I'm assuming theassert
keyword is not escaped properly during code generation and is therefore causing problems. However, I'm very new to both C++ programming and protobuf so i might be complety off.