Bug 29427 - uncallable constructor template should be warned.
Summary: uncallable constructor template should be warned.
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.1.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2006-10-11 05:35 UTC by Ivan Godard
Modified: 2012-02-02 00:39 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.4.2
Last reconfirmed: 2012-02-01 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ivan Godard 2006-10-11 05:35:55 UTC
class foo {
public:
    template<typename T>
        foo(int i) : j(i) {}
    template<typename T>
    void bar(int i) { j = i; }
    template<typename T>
    static
    void baz(int i) {}
    int j;
    };
int main() {
    foo::baz<bool>(3);
    foo* p; p->bar<bool>(3);
    new foo<bool>(3);
    return 0;
    }


gets you:
~/ootbc/chips$ g++ foo.cc
foo.cc: In function âint main()â:
foo.cc:8: error: âfooâ is not a template
foo.cc:8: error: no matching function for call to âfoo::foo(int)â
foo.cc:1: note: candidates are: foo::foo(const foo&)


The problem is that the constructor was declared as a template, hence cannot be called (see bug# 29008). This can be detected at the declaration and a warning should issue.
OK.
Comment 1 Jonathan Wakely 2009-12-08 20:45:06 UTC
diagnosing this would be useful and shouldn't require instantiation, it should be detectable during phase 1

reduced:
struct foo {
  template<typename T> foo(int);
};