Is set_value_at_thread_exit() supported on gcc? - c++

This is my first post here so please be lenient :)
I am having a problem with set_value_at_thread_exit() method from promise class (part of c++11). Everything was ok in VS2013 but GCC gives me following error message:
error: ‘class std::promise<int>’ has no member named ‘set_value_at_thread_exit’
args->result.set_value_at_thread_exit(result);
I've tried GCC 4.8 and 4.9 on Ubuntu 14.04
The code is:
[...]
int result = 0;
Socket socket;
result = CreateUDPSocket(&socket, false, ANY_IP, args->port);
if (result != ERROR_SUCCESS)
{
args->result.set_value_at_thread_exit(result);
return;
}
args->result.set_value(ERROR_SUCCESS);
[...]

Unfortunately, it isn't supported yet. If you look at the status page
30.6.5 | Class template promise | Partial | Missing set_*_at_thread_exit

Related

Why does GCC 11.1 warn about "use of possibly-NULL 'operator new(32)' where non-null expected"?

I am using GCC 11.1 and I have enabled the static analyzer with the option -fanalyzer. Now in this line:
std::pair<NodeIterator, bool> result = idNodeMap.emplace(id,
new Node(id, point));
I get the following warning:
..\src\Mesh\Mesh.cpp: In member function 'void Ct::Geometry::Mesh::addNode(int, const gp_Pnt&)':
..\src\Mesh\Mesh.cpp:30:43: warning: use of possibly-NULL 'operator new(32)' where non-null expected [CWE-690] [-Wanalyzer-possible-null-argument]
30 | new Node(id, point));
| ^
'void Ct::Geometry::Mesh::addNode(int, const gp_Pnt&)': events 1-2
|
|
In file included from ..\src\Mesh\Mesh.h:12,
from ..\src\Mesh\Mesh.cpp:9:
..\src\Mesh\Node.h:31:9: note: argument 'this' of 'Ct::Geometry::Node::Node(int, const gp_Pnt&)' must be non-null
31 | Node(int id, const gp_Pnt& point);
| ^~~~
Have I understood the warning correctly, that GCC wants me to check whether new returns null? According to this post: Will new return NULL in any case? this is never the case with current compilers and sound compilation options. So is this a warning for rare special cases and I should disable it?
Or have I overlooked something and there is a real danger in my code?
This is GCC bug #94355.
Some work has been done, but the issue is still open and there's a comment in there with this specific issue.
It sounds like it doesn't yet differentiate operator new that throws std::bad_alloc on allocation failure from (a hypothetical) one that returns nullptr.

[[maybe_unused]] and Constructors

Trying to compile the sqlpp17 codebase with gcc 8.2.1 and clang 6.0.1 have been a really strange experience. The code pushes the compilers to the limits and I hit probably a few compiler bugs in the meantime.
From the GCC Docs, [[maybe_unused]] is implemented since version 7, but if used this way:
struct foo {
foo([[maybe_unused]] bool thing1)
{
}
};
I hit this specific error:
<source>:2:9: error: expected unqualified-id before '[' token
foo([[maybe_unused]] bool thing1)
^
<source>:2:9: error: expected ')' before '[' token
foo([[maybe_unused]] bool thing1)
~^
)
Compiler returned: 1
Now, I know too little about C++17 to know if this error is correct, I know that clang 6 compiles that part fine (and fails somewhere else).
So, who's right, clang or gcc? (flags are -std=gnu++17 for both clang and gcc, generated by CMake)
This is a known bug in g++: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81429 G++ doesn't parse correctly [[maybe_unused]] attribute for first argument of the constructor.

Template Argument Deduction Broken in Clang 6 for Temporary Objects

Template argument deduction appears to be broken in Clang 6 for temporary objects.
g++ 8.1.0 compiles and runs the example correctly.
Clang 6.0.0 and 6.0.2 both error at the indicated line with this message:
error: expected unqualified-id
Print{1,"foo"s,2}; /********** Broken in Clang **********/
All Other lines work correctly.
The behavior is the same in both cases whether -std=c++17 or -std=c++2a is used.
The Clang c++ Status Page indicates that template argument deduction was implemented as of Clang 5 (P0091R3, P0512R0).
Is this a bug? Are there workarounds (e.g. compiler flags, not code changes)?
example:
template<class ...Ts>
void print(Ts...ts){ (( cout << ... << ts )); }
template<class ...Ts>
struct Print {
Print(Ts...ts){ (( cout << ... << ts )); }
};
int main(){
Print{1,"foo"s,2}; /********** Broken in Clang **********/
Print<int,string,int>{1,"foo"s,2};
auto p1 = Print{1,"foo"s,2};
Print p2{1,"foo"s,2};
print(1,"foo"s,2);
}
This is Clang bug 34091.
Luckily, it is already fixed, and the trunk build of Clang compiles this without issue.
As far as I know, however, there is currently no way to work around this without code changes, short of upgrading to the next Clang release whenever that comes out.

return type deduction and function declarations

How can I declare a function in a class that uses return type deduction?
This is fine:
auto foo() {
return 5;
}
But this does not work:
class Test {
auto foo();
};
auto Test::foo() {
return 5;
}
internal compiler error: in gen_type_die_with_usage, at dwarf2out.c:19486
I don't know if it has anything to do with it but I am using QtCreator 3.3.
EDIT:
I am using Qt 5.4 and QtCreator 3.3.
I have added CONFIG += c++14 to the project file.
By default, I am using GCC 4.8.2 and I guess this is why I get the error (I need 4.9). However when I use Clang 3.5 (3.4 is needed) it says
error: 'auto' return without trailing return type; deduced return types are a C++1y extension
EDIT2: This seems to be a bug with Qt and not with GCC. Outside of Qt I can write class functions with return type deductions and it compiles and runs just fine with GCC 4.8.2 and Clang 3.5.0

casting using llvm::dyn_cast cause in failed assertion

ERROR MESSAGE :
llvm/include/llvm/Support/Casting.h:240: typename llvm::cast_retty::ret_type llvm::cast(Y*) [with X = llvm::PointerType, Y = llvm::Type, typename llvm::cast_retty::ret_type = llvm::PointerType*]: Assertion `isa(Val) && "cast() argument of incompatible type!"' failed.
CODE :
Value *op1 = x->getOperand(0);
bool flag1;
if(ConstantInt *CI = dyn_cast<ConstantInt>(op)){
flag1=CI->isOne();
}
I searched on google and found that this was a bug but fixed. I recently downloaded the source and compiled it. Is there anyway I can fix this?
This problem is solved after using llvm 3.4 stable release. I was using latest code earlier.