compiler-warnings

how does url within function body get compiled

折月煮酒 提交于 2019-11-26 17:18:08
问题 I just pasted a url to my code, and forgot to comment it, but I was surprised to see MSVC++ compiled it successfully. My code is like this, void my_function() { http://www.google.co.in/ } How come this gets compiled by MSVC++? 回答1: Actually, http followed by a colon is treated as a label by C++, which you can use in goto statements (like goto http; ), and the rest (i.e //www.google.co.in ) is treated as single line comment. That's why it gets compiled. See more, void your_function() { http:/

Does there exist a static_warning?

梦想的初衷 提交于 2019-11-26 17:17:14
I'm aware of this question which mentions Boost's "STATIC WARNING", but I'd like to ask again, specifically, how I could implement a static_warning which operates similarly to static_assert but only emits a warning at compile time rather than an aborting compilation error. I'd like something similar to Alexandrescu's proposal for a static assert in pre-C++11 days which somehow managed to print some useful contextual information as part of the error. It would be acceptable to require that the user enable certain standard compiler warnings in order for this construction to work (perhaps "invalid

C++ Boost: what's the cause of this warning?

淺唱寂寞╮ 提交于 2019-11-26 16:23:42
问题 I have a simple C++ with Boost like this: #include <boost/algorithm/string.hpp> int main() { std::string latlonStr = "hello,ergr()()rg(rg)"; boost::find_format_all(latlonStr,boost::token_finder(boost::is_any_of("(,)")),boost::const_formatter(" ")); This works fine; it replaces every occurrence of ( ) , with a " " However, I get this warning when compiling: I'm using MSVC 2008, Boost 1.37.0. 1>Compiling... 1>mainTest.cpp 1>c:\work\minescout-feat-000\extlib\boost\algorithm\string\detail

Understanding -Weffc++

房东的猫 提交于 2019-11-26 16:17:51
问题 Consider the following program: #include <string> struct S { S (){} private: void *ptr = nullptr; std::string str = ""; }; int main(){} This, when compiled with -Weffc++ on GCC 4.7.1, will spit out: warning: 'struct S' has pointer data members [-Weffc++] warning: but does not override 'S(const S&)' [-Weffc++] warning: or 'operator=(const S&)' [-Weffc++] That's no problem normally, except for a couple things with this example: If I comment out any of the constructor, the pointer declaration,

Property getters and setters

扶醉桌前 提交于 2019-11-26 15:51:13
With this simple class I am getting the compiler warning Attempting to modify/access x within its own setter/getter and when I use it like this: var p: point = Point() p.x = 12 I get an EXC_BAD_ACCESS. How can I do this without explicit backing ivars? class Point { var x: Int { set { x = newValue * 2 //Error } get { return x / 2 //Error } } // ... } GoZoner Setters and Getters apply to computed properties ; such properties do not have storage in the instance - the value from the getter is meant to be computed from other instance properties. In your case, there is no x to be assigned.

Why should I initialize member variables in the order they&#39;re declared in?

北慕城南 提交于 2019-11-26 15:42:44
问题 I was writing some code today and got a weird compile error, which seems to be caused by initializing member variables in a different order than they were declared. Example: class Test { int a; int b; public: Test() : b(1), a(2) { } }; int main() { Test test; return 0; } Then if I compile it with -Werror -Wall : $ g++ -Werror -Wall test.cpp test.cpp: In constructor ‘Test::Test()’: test.cpp:3:9: error: ‘Test::b’ will be initialized after [-Werror=reorder] test.cpp:2:9: error: ‘int Test::a’ [

How to turn on (literally) ALL of GCC&#39;s warnings?

混江龙づ霸主 提交于 2019-11-26 15:39:48
I would like to enable -- literally -- ALL of the warnings that GCC has. (You'd think it would be easy...) You'd think -Wall might do the trick, but nope! Still need -Wextra . You'd think -Wextra might do the trick, but nope! Not all of the warnings listed here (for example, -Wshadow ) are enabled by this. And I still have no idea if this list is comprehensive. How do I tell GCC to enable (no if's, and's, or but's!) all the warnings it has? You can't. The manual for GCC 4.4.0 is only comprehensive for that version, but it does list all the possible warnings for 4.4.0. They're not all on the

Can GCC not complain about undefined references?

为君一笑 提交于 2019-11-26 15:26:07
问题 Under what situation is it possible for GCC to not throw an "undefined reference" link error message when trying to call made-up functions? For example, a situation in which this C code is compiled and linked by GCC: void function() { made_up_function_name(); return; } ...even though made_up_function_name is not present anywhere in the code (not headers, source files, declarations, nor any third party library). Can that kind of code be accepted and compiled by GCC under certain conditions,

Java Class.cast() vs. cast operator

南楼画角 提交于 2019-11-26 15:02:55
Having being taught during my C++ days about evils of the C-style cast operator I was pleased at first to find that in Java 5 java.lang.Class had acquired a cast method. I thought that finally we have an OO way of dealing with casting. Turns out Class.cast is not the same as static_cast in C++. It is more like reinterpret_cast . It will not generate a compilation error where it is expected and instead will defer to runtime. Here is a simple test case to demonstrate different behaviors. package test; import static org.junit.Assert.assertTrue; import org.junit.Test; public class TestCast {

What does “control reaches end of non-void function” mean?

非 Y 不嫁゛ 提交于 2019-11-26 12:28:25
问题 I\'ve been getting strange compiler errors on this binary search algorithm. I get a warning that control reaches end of non-void function . What does this mean? int binary(int val, int sorted[], int low, int high) { int mid = (low+high)/2; if(high < low) return -1; if(val < sorted[mid]) return binary(val, sorted, low, mid-1); else if(val > sorted[mid]) return binary(val, sorted, mid+1, high); else if(val == sorted[mid]) return mid; } 回答1: The compiler cannot tell from that code if the