compiler-bug

Is it an Rvalue or Lvalue After a Cast

有些话、适合烂在心里 提交于 2021-02-11 11:58:08
问题 The code here test for lvalue or rvalue after a type cast: #include <stdio.h> template <typename T> T const f1(T const &t) { printf("T const \n"); return t; } template <typename T> T f1(T &t) { printf("T\n"); return t; } struct KK { int a; }; int main() { KK kk; kk.a=0; int ii; f1(kk); f1((KK)kk); f1(ii); f1((int)ii); return 0; } In gcc link the result is like this indicating rvalue resulted after a type cast: T T const T T const But in VC++2010, this is the result indicating rvalue only if

Is it an Rvalue or Lvalue After a Cast

风格不统一 提交于 2021-02-11 11:56:22
问题 The code here test for lvalue or rvalue after a type cast: #include <stdio.h> template <typename T> T const f1(T const &t) { printf("T const \n"); return t; } template <typename T> T f1(T &t) { printf("T\n"); return t; } struct KK { int a; }; int main() { KK kk; kk.a=0; int ii; f1(kk); f1((KK)kk); f1(ii); f1((int)ii); return 0; } In gcc link the result is like this indicating rvalue resulted after a type cast: T T const T T const But in VC++2010, this is the result indicating rvalue only if

Braced functional cast to reference type, a hole in the standard or compilers bug?

纵饮孤独 提交于 2021-02-07 12:52:15
问题 According to the standard, a braced functional cast always results in a prvalue, [expr.cast]/2 Otherwise, the expression is a prvalue of the specified type whose result object is direct-initialized with the initializer. Which is hard to interpret when the specified type is a reference type, as it may happen in generic programming. Compiler have adopted specific behavior in this case: #include <type_traits> struct A { A ()=default; A (const A&); }; template <class T, class U> decltype(auto) f

Using C# 7.1 default literal in nullable optional argument causes unexpected behavior

只谈情不闲聊 提交于 2021-02-07 11:53:30
问题 C# 7.1 introduces a new feature called "Default Literals" that allows new default expressions. // instead of writing Foo x = default(Foo); // we can just write Foo x = default; For Nullable<T> types, the default value is null , and with the usual usage this works as expected: int? x = default(int?); // x is null int? x = default; // x is null However, when I try to use the new default literal as an optional argument (parameter) of a function, it's not working as expected: static void Foo(int?

Unexpected gcc warning: function returns address of local variable - is it a compiler bug?

会有一股神秘感。 提交于 2021-01-28 05:20:52
问题 Following is the minimum working example (ok, in fact it's minimum non-working example :-)). When compiled with gcc (from version 5.0 up to 9.3) it fires the following warning. It even seems to fire the warning only in release build ( -02 and higher). Code: class A { }; class B { const A& getA() const { static A a; return a; } const A& get(bool b) const; }; const A& B::get(bool b) const { return static_cast<const A&>(b ? getA() : getA()); } int main(int argc, char** argv) { return 0; }

[[maybe_unused]] on member variable, GCC warns (incorrectly?) that attribute is ignored

落爺英雄遲暮 提交于 2021-01-26 22:51:20
问题 In the following example: struct Foo { [[maybe_unused]] int member = 1; void bar() { [[maybe_unused]] int local = 0; } }; int main(int argc, char* argv[]) { Foo f{}; f.bar(); return 0; } GCC emits a warning where Clang and MSVC do not: warning: 'maybe_unused' attribute ignored [-Wattributes] [[maybe_unused]] int member = 1; As far as I can tell, this should be legal (and not ignored by the compiler). According to the standard: 10.6.7 Maybe unused attribute [dcl.attr.unused] ... 2. The

[[maybe_unused]] on member variable, GCC warns (incorrectly?) that attribute is ignored

自闭症网瘾萝莉.ら 提交于 2021-01-26 22:50:10
问题 In the following example: struct Foo { [[maybe_unused]] int member = 1; void bar() { [[maybe_unused]] int local = 0; } }; int main(int argc, char* argv[]) { Foo f{}; f.bar(); return 0; } GCC emits a warning where Clang and MSVC do not: warning: 'maybe_unused' attribute ignored [-Wattributes] [[maybe_unused]] int member = 1; As far as I can tell, this should be legal (and not ignored by the compiler). According to the standard: 10.6.7 Maybe unused attribute [dcl.attr.unused] ... 2. The

[[maybe_unused]] on member variable, GCC warns (incorrectly?) that attribute is ignored

不打扰是莪最后的温柔 提交于 2021-01-26 22:49:29
问题 In the following example: struct Foo { [[maybe_unused]] int member = 1; void bar() { [[maybe_unused]] int local = 0; } }; int main(int argc, char* argv[]) { Foo f{}; f.bar(); return 0; } GCC emits a warning where Clang and MSVC do not: warning: 'maybe_unused' attribute ignored [-Wattributes] [[maybe_unused]] int member = 1; As far as I can tell, this should be legal (and not ignored by the compiler). According to the standard: 10.6.7 Maybe unused attribute [dcl.attr.unused] ... 2. The

“redundant cast to java.lang.Object” warning for necessary cast

一笑奈何 提交于 2020-12-28 06:51:45
问题 Consider this Minimal, Reproducible Example : interface Code { static void main(String[] args) { symbol( String.valueOf( true ? 'a' : true ? 'b' : true ? 'c' : fail() ) ); } private static void symbol(String symbol) { System.out.println(symbol); } private static <R> R fail() { throw null; } } (Being near minimal, true is a stand in for a useful boolean expression. We can ignore beyond the first ? : (in the real code, there are lots).) This 'obviously' gives the error. 4: reference to valueOf

“redundant cast to java.lang.Object” warning for necessary cast

爱⌒轻易说出口 提交于 2020-12-28 06:49:10
问题 Consider this Minimal, Reproducible Example : interface Code { static void main(String[] args) { symbol( String.valueOf( true ? 'a' : true ? 'b' : true ? 'c' : fail() ) ); } private static void symbol(String symbol) { System.out.println(symbol); } private static <R> R fail() { throw null; } } (Being near minimal, true is a stand in for a useful boolean expression. We can ignore beyond the first ? : (in the real code, there are lots).) This 'obviously' gives the error. 4: reference to valueOf