Is it possible in Visual Studio to get a compiler error for an assignment in an if statement? How?
#include <iostream>
int main()
{
int a = 2;
if (a = 3) // Want a warning here
std::cout << "Avoid this!\n";
}
I know I can switch to Yoda conditions (if (3=a)), but I really don't want to.
I tried: setting the warning level to /Wall but I still don't get a warning that I could then treat as an error.
I am doing this in Visual Studio 2019 (16.11.19).:
The build output is
Rebuild started...
1>------ Rebuild All started: Project: Yoda2019, Configuration: Debug Win32 ------
1>Yoda2019.cpp
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\limits.h(70,5): error C2220: the following warning is treated as an error
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\limits.h(70,5): warning C4668: '__STDC_WANT_SECURE_LIB__' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\xmemory(154,5): warning C4365: 'argument': conversion from 'long' to 'unsigned int', signed/unsigned mismatch
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\xmemory(164,5): warning C4365: 'argument': conversion from 'long' to 'unsigned int', signed/unsigned mismatch
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\atomic(284,9): warning C4365: 'argument': conversion from 'long' to 'unsigned int', signed/unsigned mismatch
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\atomic(299,9): warning C4365: 'argument': conversion from 'long' to 'unsigned int', signed/unsigned mismatch
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\atomic(315,9): warning C4365: 'argument': conversion from 'long' to 'unsigned int', signed/unsigned mismatch
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\atomic(375,9): warning C4365: 'argument': conversion from 'long' to 'unsigned int', signed/unsigned mismatch
1>Done building project "Yoda2019.vcxproj" -- FAILED.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
and Visual Studio 2022 (17.4.0)
The build output is
Rebuild started...
1>------ Rebuild All started: Project: YodaCheck, Configuration: Debug x64 ------
1>YodaCheck.cpp
1>YodaCheck.vcxproj -> B:\Projekte\C++\Dynamic Linking\YodaCheck\x64\Debug\YodaCheck.exe
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
========== Elapsed 00:01,379 ==========
so I see no warning which I could convert into an error.
You can turn any specific warning into an error, using the #pragma warning(error:nnnn) directive. In your case, the warning is:
warning C4706: assignment within conditional expression
So, adding the relevant #pragma directive to the code will generate a compiler error:
#include <iostream>
#pragma warning(error:4706)
int main()
{
int a = 2;
if (a = 3) // Want a warning here
std::cout << "Avoid this!\n";
}
This now gives:
error C4706: assignment within conditional expression
For a solution wide setting, change it here in the property pages:
Use /W4 /WX
/WX Treats all compiler warnings as errors. For a new project, it may be best to use /WX in all compilations; resolving all warnings ensures the fewest possible hard-to-find code defects.
https://learn.microsoft.com/en-us/cpp/build/reference/compiler-option-warning-level?view=msvc-170
Make sure you make that setting in the relevant configurations. In such a simple demo, it's probably easiest to choose "all configurations" and "all platforms".
Is it possible in Visual Studio to get a compiler error for an assignment in an if statement? How?
#include <iostream>
int main()
{
int a = 2;
if (a = 3) // Want a warning here
std::cout << "Avoid this!\n";
}
I know I can switch to Yoda conditions (if (3=a)), but I really don't want to.
I tried: setting the warning level to /Wall but I still don't get a warning that I could then treat as an error.
I am doing this in Visual Studio 2019 (16.11.19).:
The build output is
Rebuild started...
1>------ Rebuild All started: Project: Yoda2019, Configuration: Debug Win32 ------
1>Yoda2019.cpp
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\limits.h(70,5): error C2220: the following warning is treated as an error
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\limits.h(70,5): warning C4668: '__STDC_WANT_SECURE_LIB__' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\xmemory(154,5): warning C4365: 'argument': conversion from 'long' to 'unsigned int', signed/unsigned mismatch
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\xmemory(164,5): warning C4365: 'argument': conversion from 'long' to 'unsigned int', signed/unsigned mismatch
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\atomic(284,9): warning C4365: 'argument': conversion from 'long' to 'unsigned int', signed/unsigned mismatch
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\atomic(299,9): warning C4365: 'argument': conversion from 'long' to 'unsigned int', signed/unsigned mismatch
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\atomic(315,9): warning C4365: 'argument': conversion from 'long' to 'unsigned int', signed/unsigned mismatch
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\atomic(375,9): warning C4365: 'argument': conversion from 'long' to 'unsigned int', signed/unsigned mismatch
1>Done building project "Yoda2019.vcxproj" -- FAILED.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
and Visual Studio 2022 (17.4.0)
The build output is
Rebuild started...
1>------ Rebuild All started: Project: YodaCheck, Configuration: Debug x64 ------
1>YodaCheck.cpp
1>YodaCheck.vcxproj -> B:\Projekte\C++\Dynamic Linking\YodaCheck\x64\Debug\YodaCheck.exe
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
========== Elapsed 00:01,379 ==========
so I see no warning which I could convert into an error.
You can turn any specific warning into an error, using the #pragma warning(error:nnnn) directive. In your case, the warning is:
warning C4706: assignment within conditional expression
So, adding the relevant #pragma directive to the code will generate a compiler error:
#include <iostream>
#pragma warning(error:4706)
int main()
{
int a = 2;
if (a = 3) // Want a warning here
std::cout << "Avoid this!\n";
}
This now gives:
error C4706: assignment within conditional expression
For a solution wide setting, change it here in the property pages:
Use /W4 /WX
/WX Treats all compiler warnings as errors. For a new project, it may be best to use /WX in all compilations; resolving all warnings ensures the fewest possible hard-to-find code defects.
https://learn.microsoft.com/en-us/cpp/build/reference/compiler-option-warning-level?view=msvc-170
Make sure you make that setting in the relevant configurations. In such a simple demo, it's probably easiest to choose "all configurations" and "all platforms".
Hey I'm using tensorflow c++. I built tensorflow with this. I built a GPU version. When I run the sample code, I got many errors.
I built tensorflow r2.5 and protobuf-3.9.2.
code:
#include <iostream>
#include <tensorflow/core/framework/graph.pb.h>
#include <tensorflow/core/public/session.h>
#include <tensorflow/core/public/version.h>
int main() {
std::cout << tf_git_version() << std::endl;
std::unique_ptr<tensorflow::Session> session(tensorflow::NewSession({}));
}
errors:
1>------ Build started: Project: TF_savedmodel, Configuration: Release x64 ------
1>Source.cpp
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\framework\attr_value.pb.h(687,1): warning C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\framework\node_def.pb.h(97,1): warning C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\framework\function.pb.h(300,1): warning C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\framework\function.pb.h(332,1): warning C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\framework\function.pb.h(587,1): warning C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\framework\function.pb.h(590,1): warning C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\framework\function.pb.h(621,1): warning C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\framework\function.pb.h(624,1): warning C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data
1>D:\tf_model\TF_savedmodel\include\Eigen\src\Core\arch\Default\Half.h(1,1): warning C4819: The file contains a character that cannot be represented in the current code page (950). Save the file in Unicode format to prevent data loss
1>D:\tf_model\TF_savedmodel\include\Eigen\src\Core\arch\Default\BFloat16.h(1,1): warning C4819: The file contains a character that cannot be represented in the current code page (950). Save the file in Unicode format to prevent data loss
1>D:\tf_model\TF_savedmodel\include\Eigen\src\Core\arch\Default\GenericPacketMathFunctions.h(678,1): warning C4819: The file contains a character that cannot be represented in the current code page (950). Save the file in Unicode format to prevent data loss
1>D:\tf_model\TF_savedmodel\include\Eigen\src\Core\products\GeneralBlockPanelKernel.h(2065,1): warning C4819: The file contains a character that cannot be represented in the current code page (950). Save the file in Unicode format to prevent data loss
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\platform\tstring.h(350,40): error C2589: '(': illegal token on right side of '::'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\platform\tstring.h(350): error C2062: type 'unknown-type' unexpected
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\platform\tstring.h(350,56): error C2059: syntax error: ')'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\platform\default\logging.h(383,1): warning C4003: not enough arguments for function-like macro invocation 'max'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\platform\default\logging.h(382,1): error C2589: '(': illegal token on right side of '::'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\platform\default\logging.h(383): error C2062: type 'unknown-type' unexpected
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\platform\default\logging.h(383,1): error C2059: syntax error: ')'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\platform\default\logging.h(383,1): error C2143: syntax error: missing ';' before '{'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\platform\default\logging.h(384,1): warning C4003: not enough arguments for function-like macro invocation 'max'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\platform\default\logging.h(384,1): error C2589: '(': illegal token on right side of '::'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\platform\default\logging.h(384): error C2062: type 'unknown-type' unexpected
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\platform\default\logging.h(384,1): error C2059: syntax error: ')'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\platform\default\logging.h(384,1): error C2143: syntax error: missing ';' before '{'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\platform\default\logging.h(385,1): warning C4003: not enough arguments for function-like macro invocation 'max'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\platform\default\logging.h(385,1): error C2589: '(': illegal token on right side of '::'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\platform\default\logging.h(385): error C2062: type 'unknown-type' unexpected
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\platform\default\logging.h(385,1): error C2059: syntax error: ')'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\platform\default\logging.h(385,1): error C2143: syntax error: missing ';' before '{'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\platform\default\logging.h(386,1): warning C4003: not enough arguments for function-like macro invocation 'max'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\platform\default\logging.h(386,1): error C2589: '(': illegal token on right side of '::'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\platform\default\logging.h(386): error C2062: type 'unknown-type' unexpected
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\platform\default\logging.h(386,1): error C2059: syntax error: ')'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\platform\default\logging.h(386,1): error C2143: syntax error: missing ';' before '{'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\platform\default\logging.h(387,1): warning C4003: not enough arguments for function-like macro invocation 'max'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\platform\default\logging.h(387,1): error C2589: '(': illegal token on right side of '::'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\platform\default\logging.h(387): error C2062: type 'unknown-type' unexpected
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\platform\default\logging.h(387,1): error C2059: syntax error: ')'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\platform\default\logging.h(387,1): error C2143: syntax error: missing ';' before '{'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\platform\default\logging.h(388,1): warning C4003: not enough arguments for function-like macro invocation 'max'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\platform\default\logging.h(388,1): error C2589: '(': illegal token on right side of '::'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\platform\default\logging.h(388): error C2062: type 'unknown-type' unexpected
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\platform\default\logging.h(388,1): error C2059: syntax error: ')'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\platform\default\logging.h(388,1): error C2143: syntax error: missing ';' before '{'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\error_codes.pb.h(80,92): warning C4003: not enough arguments for function-like macro invocation 'min'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\error_codes.pb.h(80,92): error C2589: '(': illegal token on right side of '::'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\error_codes.pb.h(80): error C2062: type 'unknown-type' unexpected
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\error_codes.pb.h(80,92): error C3805: 'type': unexpected token, expected either '}' or a ','
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\error_codes.pb.h(81,92): warning C4003: not enough arguments for function-like macro invocation 'max'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\framework\tensor_shape.h(106,67): warning C4003: not enough arguments for function-like macro invocation 'max'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\framework\tensor_shape.h(106,67): error C2589: '(': illegal token on right side of '::'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\framework\tensor_shape.h(106): error C2062: type 'unknown-type' unexpected
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\framework\tensor_shape.h(106,67): error C2737: 'protected: static __int64 const tensorflow::TensorShapeRep::kMaxRep16': constexpr object must be initialized
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\framework\tensor_shape.h(106,67): error C2059: syntax error: ')'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\framework\tensor_shape.h(107,67): warning C4003: not enough arguments for function-like macro invocation 'max'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\framework\tensor_shape.h(107,67): error C2589: '(': illegal token on right side of '::'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\framework\tensor_shape.h(107): error C2062: type 'unknown-type' unexpected
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\framework\tensor_shape.h(107,67): error C2737: 'protected: static __int64 const tensorflow::TensorShapeRep::kMaxRep32': constexpr object must be initialized
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\framework\tensor_shape.h(107,67): error C2059: syntax error: ')'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\framework\tensor_shape.h(108,72): warning C4003: not enough arguments for function-like macro invocation 'max'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\framework\tensor_shape.h(108,72): error C2589: '(': illegal token on right side of '::'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\framework\tensor_shape.h(108): error C2062: type 'unknown-type' unexpected
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\framework\tensor_shape.h(108,72): error C2737: 'protected: static unsigned short const tensorflow::TensorShapeRep::kUnknownRep16': constexpr object must be initialized
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\framework\tensor_shape.h(108,72): error C2059: syntax error: ')'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\framework\tensor_shape.h(109,72): warning C4003: not enough arguments for function-like macro invocation 'max'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\framework\tensor_shape.h(109,72): error C2589: '(': illegal token on right side of '::'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\framework\tensor_shape.h(109): error C2062: type 'unknown-type' unexpected
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\framework\tensor_shape.h(109,72): error C2737: 'protected: static unsigned int const tensorflow::TensorShapeRep::kUnknownRep32': constexpr object must be initialized
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\framework\tensor_shape.h(109,72): error C2059: syntax error: ')'
1>D:\tf_model\TF_savedmodel\include\unsupported\Eigen\CXX11\src\Tensor\Tensor.h(76,1): warning C4554: '&': check operator precedence for possible error; use parentheses to clarify precedence
1>D:\tf_model\TF_savedmodel\include\unsupported\Eigen\CXX11\src\Tensor\TensorMap.h(43): message : see reference to class template instantiation 'Eigen::Tensor<T,1,1,int>' being compiled
1> with
1> [
1> T=float
1> ]
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\framework\tensor_types.h(105): message : see reference to class template instantiation 'Eigen::TensorMap<Eigen::Tensor<T,1,1,int>,16,Eigen::MakePointer>' being compiled
1> with
1> [
1> T=float
1> ]
1>D:\tf_model\TF_savedmodel\include\google\protobuf\type.pb.h(106,109): warning C4003: not enough arguments for function-like macro invocation 'min'
1>D:\tf_model\TF_savedmodel\include\google\protobuf\type.pb.h(106,109): error C2589: '(': illegal token on right side of '::'
1>D:\tf_model\TF_savedmodel\include\google\protobuf\type.pb.h(106): error C2062: type 'unknown-type' unexpected
1>D:\tf_model\TF_savedmodel\include\google\protobuf\type.pb.h(106,109): error C3805: 'type': unexpected token, expected either '}' or a ','
1>D:\tf_model\TF_savedmodel\include\google\protobuf\type.pb.h(107,109): warning C4003: not enough arguments for function-like macro invocation 'max'
1>D:\tf_model\TF_savedmodel\include\google\protobuf\type.pb.h(133,123): warning C4003: not enough arguments for function-like macro invocation 'min'
1>D:\tf_model\TF_savedmodel\include\google\protobuf\type.pb.h(133,123): error C2589: '(': illegal token on right side of '::'
1>D:\tf_model\TF_savedmodel\include\google\protobuf\type.pb.h(133): error C2062: type 'unknown-type' unexpected
1>D:\tf_model\TF_savedmodel\include\google\protobuf\type.pb.h(133,123): error C3805: 'type': unexpected token, expected either '}' or a ','
1>D:\tf_model\TF_savedmodel\include\google\protobuf\type.pb.h(134,123): warning C4003: not enough arguments for function-like macro invocation 'max'
1>D:\tf_model\TF_savedmodel\include\google\protobuf\type.pb.h(158,94): warning C4003: not enough arguments for function-like macro invocation 'min'
1>D:\tf_model\TF_savedmodel\include\google\protobuf\type.pb.h(158,94): error C2589: '(': illegal token on right side of '::'
1>D:\tf_model\TF_savedmodel\include\google\protobuf\type.pb.h(158): error C2062: type 'unknown-type' unexpected
1>D:\tf_model\TF_savedmodel\include\google\protobuf\type.pb.h(158,94): error C3805: 'type': unexpected token, expected either '}' or a ','
1>D:\tf_model\TF_savedmodel\include\google\protobuf\type.pb.h(159,94): warning C4003: not enough arguments for function-like macro invocation 'max'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\platform\tensor_coding.h(47,38): error C2589: '(': illegal token on right side of '::'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\platform\tensor_coding.h(47): error C2062: type 'unknown-type' unexpected
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\platform\tensor_coding.h(47,62): error C2059: syntax error: ')'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\framework\step_stats.pb.h(1180,1): warning C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\cluster.pb.h(97,1): warning C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\verifier_config.pb.h(72,131): warning C4003: not enough arguments for function-like macro invocation 'min'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\verifier_config.pb.h(72,131): error C2589: '(': illegal token on right side of '::'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\verifier_config.pb.h(72): error C2062: type 'unknown-type' unexpected
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\verifier_config.pb.h(72,131): error C3805: 'type': unexpected token, expected either '}' or a ','
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\verifier_config.pb.h(73,131): warning C4003: not enough arguments for function-like macro invocation 'max'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\rewriter_config.pb.h(94,131): warning C4003: not enough arguments for function-like macro invocation 'min'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\rewriter_config.pb.h(94,131): error C2589: '(': illegal token on right side of '::'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\rewriter_config.pb.h(94): error C2062: type 'unknown-type' unexpected
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\rewriter_config.pb.h(94,131): error C3805: 'type': unexpected token, expected either '}' or a ','
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\rewriter_config.pb.h(95,131): warning C4003: not enough arguments for function-like macro invocation 'max'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\rewriter_config.pb.h(120,137): warning C4003: not enough arguments for function-like macro invocation 'min'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\rewriter_config.pb.h(120,137): error C2589: '(': illegal token on right side of '::'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\rewriter_config.pb.h(120): error C2062: type 'unknown-type' unexpected
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\rewriter_config.pb.h(120,137): error C3805: 'type': unexpected token, expected either '}' or a ','
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\rewriter_config.pb.h(121,137): warning C4003: not enough arguments for function-like macro invocation 'max'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\rewriter_config.pb.h(146,153): warning C4003: not enough arguments for function-like macro invocation 'min'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\rewriter_config.pb.h(146,153): error C2589: '(': illegal token on right side of '::'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\rewriter_config.pb.h(146): error C2062: type 'unknown-type' unexpected
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\rewriter_config.pb.h(146,153): error C3805: 'type': unexpected token, expected either '}' or a ','
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\rewriter_config.pb.h(147,153): warning C4003: not enough arguments for function-like macro invocation 'max'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\rewriter_config.pb.h(176,139): warning C4003: not enough arguments for function-like macro invocation 'min'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\rewriter_config.pb.h(176,139): error C2589: '(': illegal token on right side of '::'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\rewriter_config.pb.h(176): error C2062: type 'unknown-type' unexpected
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\rewriter_config.pb.h(176,139): error C3805: 'type': unexpected token, expected either '}' or a ','
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\rewriter_config.pb.h(177,139): warning C4003: not enough arguments for function-like macro invocation 'max'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\rewriter_config.pb.h(543,1): warning C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\config.pb.h(156,133): warning C4003: not enough arguments for function-like macro invocation 'min'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\config.pb.h(156,133): error C2589: '(': illegal token on right side of '::'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\config.pb.h(156): error C2062: type 'unknown-type' unexpected
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\config.pb.h(156,133): error C3805: 'type': unexpected token, expected either '}' or a ','
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\config.pb.h(157,133): warning C4003: not enough arguments for function-like macro invocation 'max'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\config.pb.h(183,151): warning C4003: not enough arguments for function-like macro invocation 'min'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\config.pb.h(183,151): error C2589: '(': illegal token on right side of '::'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\config.pb.h(183): error C2062: type 'unknown-type' unexpected
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\config.pb.h(183,151): error C3805: 'type': unexpected token, expected either '}' or a ','
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\config.pb.h(184,151): warning C4003: not enough arguments for function-like macro invocation 'max'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\config.pb.h(211,173): warning C4003: not enough arguments for function-like macro invocation 'min'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\config.pb.h(211,173): error C2589: '(': illegal token on right side of '::'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\config.pb.h(211): error C2062: type 'unknown-type' unexpected
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\config.pb.h(211,173): error C3805: 'type': unexpected token, expected either '}' or a ','
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\config.pb.h(212,173): warning C4003: not enough arguments for function-like macro invocation 'max'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\config.pb.h(238,131): warning C4003: not enough arguments for function-like macro invocation 'min'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\config.pb.h(238,131): error C2589: '(': illegal token on right side of '::'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\config.pb.h(238): error C2062: type 'unknown-type' unexpected
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\config.pb.h(238,131): error C3805: 'type': unexpected token, expected either '}' or a ','
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\config.pb.h(239,131): warning C4003: not enough arguments for function-like macro invocation 'max'
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\config.pb.h(1951,1): warning C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\config.pb.h(3797,1): warning C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\config.pb.h(3800,1): warning C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\config.pb.h(3831,1): warning C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\protobuf\config.pb.h(3834,1): warning C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data
1>D:\tf_model\TF_savedmodel\include\tensorflow\core\public\session_options.h(62,2): warning C4091: '__declspec(dllimport)': ignored on left of 'tensorflow::SessionOptions' when no variable is declared
1>Done building project "TF_savedmodel.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Some said this happened because of "Windows.h", but I didn't saw such a include command in these header files. Should I edit some of those files?
If someone could tell me how to solve that, it will be nice.
[solved] just add () to following files which using std::XXX::min/ max().
I'm trying to build a solution using Boost in Visual Studio C++ Express 2010 and get the following error:
1>------ Build started: Project: MEDsLDAc, Configuration: Release Win32 ------
1> MedLDA.cpp
1>D:\_download\boost_1_53_0\boost/math/constants/calculate_constants.hpp(152): error C2988: unrecognizable template declaration/definition
1>D:\_download\boost_1_53_0\boost/math/constants/calculate_constants.hpp(152): error C2059: syntax error : 'constant'
1>D:\_download\boost_1_53_0\boost/math/constants/calculate_constants.hpp(153): error C2143: syntax error : missing ')' before '>'
1>D:\_download\boost_1_53_0\boost/math/constants/calculate_constants.hpp(184): error C2244: 'boost::math::constants::detail::constant_euler<T>::compute' : unable to match function definition to an existing declaration
1> definition
1> 'T boost::math::constants::detail::constant_euler<T>::compute(void)'
1> existing declarations
1> 'T boost::math::constants::detail::constant_euler<T>::compute(void)'
1>MedLDA.cpp(385): warning C4244: 'initializing' : conversion from 'double' to 'long', possible loss of data
1>MedLDA.cpp(426): warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> C:\Program Files\Microsoft Visual Studio 10.0\VC\include\string.h(105) : see declaration of 'strcpy'
1>MedLDA.cpp(485): warning C4244: 'initializing' : conversion from 'double' to 'long', possible loss of data
1>MedLDA.cpp(608): warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> C:\Program Files\Microsoft Visual Studio 10.0\VC\include\string.h(105) : see declaration of 'strcpy'
1>MedLDA.cpp(609): warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> C:\Program Files\Microsoft Visual Studio 10.0\VC\include\string.h(105) : see declaration of 'strcpy'
1>MedLDA.cpp(636): warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> C:\Program Files\Microsoft Visual Studio 10.0\VC\include\string.h(105) : see declaration of 'strcpy'
1>MedLDA.cpp(730): warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
1>MedLDA.cpp(963): warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
1>MedLDA.cpp(1150): warning C4244: 'initializing' : conversion from 'double' to 'int', possible loss of data
1>MedLDA.cpp(1241): warning C4244: 'initializing' : conversion from 'double' to 'long', possible loss of data
1>MedLDA.cpp(1296): warning C4244: 'initializing' : conversion from 'double' to 'long', possible loss of data
========== Build: 0 succeeded, 1 failed, 2 up-to-date, 0 skipped ==========
How to fix it?
UPDATE: the software is MedLDAc available here:
http://www.ml-thu.net/~jun/medlda.shtml
The author says building works for him.
Since you haven't shown any code, we can only guess. My guess is that you #define some macro that messes-up Boost.Math code. Maybe something like #define M ......
UPDATE: It turns out that my guess was correct. Take a look at MedLDAc/MEDsLDAc/cokus.h file:
#define M (397) // a period parameter
The immediate workaround is to move #include <boost/math/special_functions/gamma.hpp> line in MedLDA.cpp to be the first include, after StdAfx.h, so that the above macro wouldn't affect the templates declared in gamma.hpp.
P.S. Defining one-letter macros is a really, really bad idea.