public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/44906]  New: g++ is giving error: parse error in template argument list while using a c++ code.
@ 2010-07-10 15:43 raychaudhuri_amitava at yahoo dot com
  2010-07-10 15:44 ` [Bug c++/44906] " raychaudhuri_amitava at yahoo dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 10+ messages in thread
From: raychaudhuri_amitava at yahoo dot com @ 2010-07-10 15:43 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 6713 bytes --]

amitavac@whileliesent-lm:~/data/prog/c++/template_ptr$g++ -v -o template
template.cpp 
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.4.3-4ubuntu5'
--with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared
--enable-multiarch --enable-linker-build-id --with-system-zlib
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls
--enable-clocale=gnu --enable-libstdcxx-debug --enable-plugin --enable-objc-gc
--enable-targets=all --disable-werror --with-arch-32=i486 --with-tune=generic
--enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu
--target=i486-linux-gnu
Thread model: posix
gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5) 
COLLECT_GCC_OPTIONS='-v' '-o' 'template' '-shared-libgcc' '-mtune=generic'
'-march=i486'
 /usr/lib/gcc/i486-linux-gnu/4.4.3/cc1plus -quiet -v -D_GNU_SOURCE template.cpp
-D_FORTIFY_SOURCE=2 -quiet -dumpbase template.cpp -mtune=generic -march=i486
-auxbase template -version -fstack-protector -o /tmp/ccZiqQ9b.s
GNU C++ (Ubuntu 4.4.3-4ubuntu5) version 4.4.3 (i486-linux-gnu)
        compiled by GNU C version 4.4.3, GMP version 4.3.2, MPFR version
2.4.2-p1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/include/i486-linux-gnu"
ignoring nonexistent directory
"/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../i486-linux-gnu/include"
ignoring nonexistent directory "/usr/include/i486-linux-gnu"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/4.4
 /usr/include/c++/4.4/i486-linux-gnu
 /usr/include/c++/4.4/backward
 /usr/local/include
 /usr/lib/gcc/i486-linux-gnu/4.4.3/include
 /usr/lib/gcc/i486-linux-gnu/4.4.3/include-fixed
 /usr/include
End of search list.
GNU C++ (Ubuntu 4.4.3-4ubuntu5) version 4.4.3 (i486-linux-gnu)
        compiled by GNU C version 4.4.3, GMP version 4.3.2, MPFR version
2.4.2-p1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 35224f2c24023afb0a5be7befe8d5f3f
template.cpp: In member function ‘void MISC<T, P>::add(int)’:
template.cpp:55: error: parse error in template argument list
template.cpp:58: error: parse error in template argument list
template.cpp:61: error: parse error in template argument list
template.cpp:64: error: parse error in template argument list
template.cpp: In member function ‘void MISC<T, P>::print(int)’:
template.cpp:72: error: parse error in template argument list
template.cpp:75: error: parse error in template argument list
template.cpp:78: error: parse error in template argument list
template.cpp:81: error: parse error in template argument list

Following is the content of template.cpp (please let me know whats wrong with
the following program):
#include<stdint.h>

#include<iostream>
#include<vector>
#include<set>

using namespace std;

template<typename T, typename P>
class MISC{
        private:
                vector<T> vec1;
                vector<T> vec2;

                set<T> st1;
                set<T> st2;

                vector<P> *ptr;
        private:
                template<vector<T>* vc>
                        void addVecVals(){
                                for(T i=0; i<10;i++)
                                {
                                        vc->push_back(i);
                                }
                        }

                template<set<T>* st>
                        void addStVals(){
                                for(T i=0; i<10;i++)
                                {
                                        st->insert(i);
                                }
                        }

                template<vector<T>* vc>
                        void printVecVals(){
                                for(typename vector<T>::iterator i=vc->begin(),
j=vc->end(); i!=j;++i)
                                {
                                        cout<<"val = "<<*i<<" , ";
                                }
                        }

                template<set<T>* st>
                        void printStVals(){
                                for(typename set<T>::iterator i=st->begin(),
j=st->end(); i!=j;++i)
                                {
                                        cout<<"val = "<<*i<<" , ";
                                }
                        }
        public:
                void add(int vecNum) {
                        switch(vecNum) {
                                case 0: //vecs.
                                        addVecVals<&vec1>();
                                        break;
                                case 1:
                                        addVecVals<&vec2>();
                                        break;
                                case 2: //sets
                                        addStVals<&st1>();
                                        break;
                                case 3:
                                        addStVals<&st2>();
                                        break;
                                default: break;
                        }
                }
                void print(int vecNum) {
                        switch(vecNum) {
                                case 0: //vecs.
                                        printVecVals<&vec1>();
                                        break;
                                case 1:
                                        printVecVals<&vec2>();
                                        break;
                                case 2: //sets
                                        printStVals<&st1>();
                                        break;
                                case 3:
                                        printStVals<&st2>();
                                        break;
                                default: break;
                        }
                }
};

int main(void) {
        MISC<uint64_t, double> m;
        m.add(0);
        m.add(1);
        m.add(2);
        m.add(3);
        return 0;
}


-- 
           Summary: g++ is giving error: parse error in template argument
                    list while using a c++ code.
           Product: gcc
           Version: 4.4.3
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: raychaudhuri_amitava at yahoo dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44906


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/44906] g++ is giving error: parse error in template argument list while using a c++ code.
  2010-07-10 15:43 [Bug c++/44906] New: g++ is giving error: parse error in template argument list while using a c++ code raychaudhuri_amitava at yahoo dot com
@ 2010-07-10 15:44 ` raychaudhuri_amitava at yahoo dot com
  2010-07-10 15:45 ` raychaudhuri_amitava at yahoo dot com
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: raychaudhuri_amitava at yahoo dot com @ 2010-07-10 15:44 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from raychaudhuri_amitava at yahoo dot com  2010-07-10 15:44 -------
Created an attachment (id=21176)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=21176&action=view)
Code which is failing.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44906


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/44906] g++ is giving error: parse error in template argument list while using a c++ code.
  2010-07-10 15:43 [Bug c++/44906] New: g++ is giving error: parse error in template argument list while using a c++ code raychaudhuri_amitava at yahoo dot com
  2010-07-10 15:44 ` [Bug c++/44906] " raychaudhuri_amitava at yahoo dot com
  2010-07-10 15:45 ` raychaudhuri_amitava at yahoo dot com
@ 2010-07-10 15:45 ` raychaudhuri_amitava at yahoo dot com
  2010-07-10 17:46 ` pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: raychaudhuri_amitava at yahoo dot com @ 2010-07-10 15:45 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from raychaudhuri_amitava at yahoo dot com  2010-07-10 15:45 -------
Created an attachment (id=21178)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=21178&action=view)
.ii file generated by -save-temps


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44906


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/44906] g++ is giving error: parse error in template argument list while using a c++ code.
  2010-07-10 15:43 [Bug c++/44906] New: g++ is giving error: parse error in template argument list while using a c++ code raychaudhuri_amitava at yahoo dot com
  2010-07-10 15:44 ` [Bug c++/44906] " raychaudhuri_amitava at yahoo dot com
@ 2010-07-10 15:45 ` raychaudhuri_amitava at yahoo dot com
  2010-07-10 15:45 ` raychaudhuri_amitava at yahoo dot com
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: raychaudhuri_amitava at yahoo dot com @ 2010-07-10 15:45 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from raychaudhuri_amitava at yahoo dot com  2010-07-10 15:44 -------
Created an attachment (id=21177)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=21177&action=view)
.s file generated by -save-temps


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44906


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/44906] g++ is giving error: parse error in template argument list while using a c++ code.
  2010-07-10 15:43 [Bug c++/44906] New: g++ is giving error: parse error in template argument list while using a c++ code raychaudhuri_amitava at yahoo dot com
                   ` (2 preceding siblings ...)
  2010-07-10 15:45 ` raychaudhuri_amitava at yahoo dot com
@ 2010-07-10 17:46 ` pinskia at gcc dot gnu dot org
  2010-07-10 18:45 ` raychaudhuri_amitava at yahoo dot com
  2010-07-10 22:19 ` paolo dot carlini at oracle dot com
  5 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2010-07-10 17:46 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pinskia at gcc dot gnu dot org  2010-07-10 17:46 -------
The error message is not clear.  The issue is that you are not using a constant
expression for a template arugment.  Template arguments are either constant
expressions or types.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44906


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/44906] g++ is giving error: parse error in template argument list while using a c++ code.
  2010-07-10 15:43 [Bug c++/44906] New: g++ is giving error: parse error in template argument list while using a c++ code raychaudhuri_amitava at yahoo dot com
                   ` (3 preceding siblings ...)
  2010-07-10 17:46 ` pinskia at gcc dot gnu dot org
@ 2010-07-10 18:45 ` raychaudhuri_amitava at yahoo dot com
  2010-07-10 22:19 ` paolo dot carlini at oracle dot com
  5 siblings, 0 replies; 10+ messages in thread
From: raychaudhuri_amitava at yahoo dot com @ 2010-07-10 18:45 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from raychaudhuri_amitava at yahoo dot com  2010-07-10 18:45 -------
(In reply to comment #4)
> The error message is not clear.  The issue is that you are not using a constant
> expression for a template arugment.  Template arguments are either constant
> expressions or types.
> 

Whenever I will be using this kind of template in a class, the variable name is
predefined. Now when I create an object and call the function, it will get the
address offset and thus should be able to create an instance of that function
with same prototype but different body, else for such cases we have to create
different functions for each member. 

Can it be a new feature in g++ compiler? This will make function and objects as
first class citizen in C++. We can create function at runtime with different
object embedded in it. (I know it can be done by #define, but this is a better
way I think.)


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44906


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/44906] g++ is giving error: parse error in template argument list while using a c++ code.
  2010-07-10 15:43 [Bug c++/44906] New: g++ is giving error: parse error in template argument list while using a c++ code raychaudhuri_amitava at yahoo dot com
                   ` (4 preceding siblings ...)
  2010-07-10 18:45 ` raychaudhuri_amitava at yahoo dot com
@ 2010-07-10 22:19 ` paolo dot carlini at oracle dot com
  5 siblings, 0 replies; 10+ messages in thread
From: paolo dot carlini at oracle dot com @ 2010-07-10 22:19 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from paolo dot carlini at oracle dot com  2010-07-10 22:19 -------
Honestly, nothing similar will happen any time soon, it means changing
completely the semantics of templates. Maybe we can produce a better
diagnostics, let's add Manuel in CC to hear his opinion...


-- 

paolo dot carlini at oracle dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manu at gcc dot gnu dot org
           Severity|major                       |enhancement
           Keywords|                            |diagnostic


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44906


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/44906] g++ is giving error: parse error in template argument list while using a c++ code.
       [not found] <bug-44906-4@http.gcc.gnu.org/bugzilla/>
  2011-09-23 12:55 ` paolo.carlini at oracle dot com
  2011-09-23 14:11 ` manu at gcc dot gnu.org
@ 2011-09-23 14:53 ` paolo.carlini at oracle dot com
  2 siblings, 0 replies; 10+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-09-23 14:53 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44906

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
   Last reconfirmed|                            |2011-09-23
         Resolution|INVALID                     |
     Ever Confirmed|0                           |1

--- Comment #9 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-09-23 14:43:26 UTC ---
Hey, you woke up! ;) Sure, let's re-open is a diagnostic issue, your call.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/44906] g++ is giving error: parse error in template argument list while using a c++ code.
       [not found] <bug-44906-4@http.gcc.gnu.org/bugzilla/>
  2011-09-23 12:55 ` paolo.carlini at oracle dot com
@ 2011-09-23 14:11 ` manu at gcc dot gnu.org
  2011-09-23 14:53 ` paolo.carlini at oracle dot com
  2 siblings, 0 replies; 10+ messages in thread
From: manu at gcc dot gnu.org @ 2011-09-23 14:11 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44906

--- Comment #8 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2011-09-23 13:59:07 UTC ---
(In reply to comment #6)
> Honestly, nothing similar will happen any time soon, it means changing
> completely the semantics of templates. Maybe we can produce a better
> diagnostics, let's add Manuel in CC to hear his opinion...

The code is invalid but the diagnostic could be much better (I only have GCC
4.5.2, so perhaps it is better in trunk).

Smaller testcase:

template<typename T>
class MISC{
public:
    T vec1;
    template<T* vc> void addVecVals(){};
    void add(void) { addVecVals<&vec1>();  };
};

void foo(void) {
    MISC<int> m;
    m.add();
}

Clang++ gives a somewhat better message:

/tmp/webcompile/_14512_0.cc:6:22: error: no matching member function for call
to 'addVecVals'
    void add(void) { addVecVals<&vec1>();  };
                     ^~~~~~~~~~~~~~~~~
/tmp/webcompile/_14512_0.cc:11:7: note: in instantiation of member function
'MISC<int>::add' requested here
    m.add();
      ^
/tmp/webcompile/_14512_0.cc:5:26: note: candidate template ignored: invalid
explicitly-specified argument for template parameter 'vc'
    template<T* vc> void addVecVals(){};
                         ^
1 error generated.


I would argue for reopening it...


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/44906] g++ is giving error: parse error in template argument list while using a c++ code.
       [not found] <bug-44906-4@http.gcc.gnu.org/bugzilla/>
@ 2011-09-23 12:55 ` paolo.carlini at oracle dot com
  2011-09-23 14:11 ` manu at gcc dot gnu.org
  2011-09-23 14:53 ` paolo.carlini at oracle dot com
  2 siblings, 0 replies; 10+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-09-23 12:55 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44906

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID

--- Comment #7 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-09-23 12:43:53 UTC ---
Closing as invalid.


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2011-09-23 14:44 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-10 15:43 [Bug c++/44906] New: g++ is giving error: parse error in template argument list while using a c++ code raychaudhuri_amitava at yahoo dot com
2010-07-10 15:44 ` [Bug c++/44906] " raychaudhuri_amitava at yahoo dot com
2010-07-10 15:45 ` raychaudhuri_amitava at yahoo dot com
2010-07-10 15:45 ` raychaudhuri_amitava at yahoo dot com
2010-07-10 17:46 ` pinskia at gcc dot gnu dot org
2010-07-10 18:45 ` raychaudhuri_amitava at yahoo dot com
2010-07-10 22:19 ` paolo dot carlini at oracle dot com
     [not found] <bug-44906-4@http.gcc.gnu.org/bugzilla/>
2011-09-23 12:55 ` paolo.carlini at oracle dot com
2011-09-23 14:11 ` manu at gcc dot gnu.org
2011-09-23 14:53 ` paolo.carlini at oracle dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).