Indiana Unversity logo[ConceptGCC]

ConceptGCC :

Re: function throw requirements

From: Doug Gregor (dgregor_at_[hidden])
Date: 2008-09-09 10:14:19


On Sep 7, 2008, at 11:36 AM, Simon Hill wrote:
> I was trying to create a concept requiring a function to be declared
> as throws nothing. However, ConceptGCC concepts seem to accept
> mismatched throw clauses in functions.
>
> =====================
> This compiles, but should it?
> =====================
> auto concept XFoo<typename T> {
> void T::bar() throw();
> };
>
> template <XFoo T>
> class CBam {};
>
> class CZug {
> public:
> void bar() throw(int) {} // this version of bar() doesn't match
> that in XFoo. Removing this line causes compilation error.
> };
>
> int main() {
>
> CBam<CZug> a; // CZug shouldn't be an XFoo since their bar()
> thrown exceptions don't match. So IMHO this shouldn't compile.
>
> return 0;
> }
> =====================
>
> Are concepts supposed to ignore function throw requirements?

Actually, function throw requirements are ill-formed on an associated
function type. Remember that function throw requirements are never
statically checked in C++; they only affect how the run-time works.
What you're trying to do is to make them checked at compile time.
Granted, that's a reasonable thing to do, but it's not what C++ does :)

> Or is this something that is coming to ConceptGCC, but isn't yet
> implemented?
> Or this a bug with ConceptGCC?

Yes, it's a bug: ConceptGCC should produce an error if an associated
function has a throw-specifier.

        - Doug