Why does the noexcept operator take an expression rather than a function signature/declaration?
Consider the following dummy example:
#include <string>
void strProcessor(const std::string& str) noexcept(true) { };
struct Type{
void method1() noexcept(strProcessor("")) { //Error: Call to nonconstexpr function
strProcessor("");
}
};
It won't compile because method1 has a non-constexpr expression in its noexcept, but why do I need to put an expression in there in the first place?
All I want to do is tell the compiler that method1 is noexcept iff an invocation of strProcessor with a succesfully constructed string is noexcept (which it is).
So why not noexcept(void strProcessor(const std::string&))?
Another similar dummy example:
struct Type{
Type(bool shouldThrow=false) noexcept(false) { if(shouldThrow) throw "error"; };
void method1() noexcept(true) {};
void method2() noexcept(noexcept(Type().method1())) { method1(); };
}
Here I'd like to say method2 is noexcept iff invoking method1 on a succesfully constructed instance of Type is noexcept (which it is in this case), but Type isn't even complete at the point where method2 id defined.
Please explain if my understanding of this feature is wrong.