-
-
Save pixie-grasper/56ecefdc0d68b07844f7 to your computer and use it in GitHub Desktop.
memo: nullptr confuses decltype(auto).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <malloc.h> | |
template <typename T> | |
auto my_alloc() -> decltype(auto) { | |
auto ret = static_cast<T*>(malloc(sizeof(T))); | |
if (ret == NULL) { | |
return nullptr; | |
} | |
return ret; | |
} | |
int main() { | |
auto a = my_alloc<int>(); | |
free(a); | |
return 0; | |
} |
I've checked another env, failed.
$ clang++ 1.cc -std=c++1y
1.cc:10:3: error: 'decltype(auto)' in return type deduced as 'int *' here but
deduced as 'nullptr_t' in earlier return statement
return ret;
^
1.cc:14:12: note: in instantiation of function template specialization
'my_alloc<int>' requested here
auto a = my_alloc<int>();
^
1 error generated.
$ clang++ --version
clang version 3.5.0 (220663)
Target: x86_64-unknown-linux-gnu
Thread model: posix
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's not compilable on my env. How about on yours?
I've checked on there, but get errored.
clang version 3.4.2 (tags/RELEASE_34/dot2-final)
Target: i386-pc-cygwin
Thread model: posix