https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81260
Bug ID: 81260
Summary: Error "taking address of temporary" is missing
Product: gcc
Version: 5.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: carljohnson95 at gmx dot com
Target Milestone: ---
Command line:
>c++ main.cpp -std=c++14 -Wall -Wextra -Wpedantic -fno-strict-aliasing -fwrapv
>-o 1.exe
Compiler output:
main.cpp: In function 'int main()':
main.cpp:10:22: error: taking address of temporary [-fpermissive]
cout << (int)&((A)1) << endl; // error: taking address of temporary
This is the code:
// BEGIN
#include <iostream>
using namespace std;
class A{public:
A(int a){this->a = a;}
int a;
};
int main(void){
cout << (int)&((A)1) << endl; // error: taking address of temporary
cout << (int)&((A)1 = 1) << endl; // No error
}
// END
According to the specs, shouldn't the second throw an error too? (assuming that
sizeof(A*)==sizeof(int))