public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [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
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 11+ 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] 11+ 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 ` [Bug c++/44906] g++ is giving error: parse error in template argument list while using a c++ code 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 subsequent siblings)
  4 siblings, 0 replies; 11+ 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] 11+ 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 ` [Bug c++/44906] g++ is giving error: parse error in template argument list while using a c++ code 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
  2011-10-19 22:24 ` [Bug c++/44906] g++ is giving error: parse error in template argument list manu at gcc dot gnu.org
  2021-08-04  6:20 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 11+ 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] 11+ messages in thread

* [Bug c++/44906] g++ is giving error: parse error in template argument list
       [not found] <bug-44906-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2011-09-23 14:53 ` paolo.carlini at oracle dot com
@ 2011-10-19 22:24 ` manu at gcc dot gnu.org
  2021-08-04  6:20 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 11+ messages in thread
From: manu at gcc dot gnu.org @ 2011-10-19 22:24 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2011-10-19 22:24:12 UTC ---
The problem seems to be the tentative parsing in cp_parse_template_id, which
tries every crazy thing it can, and when nothing works, it just gives this
catch all diagnostic. 

But debugging the C++ parser is an absolute pain, I hope someone with more
patience takes a shot at this. The current diagnostic is just awful.


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

* [Bug c++/44906] g++ is giving error: parse error in template argument list
       [not found] <bug-44906-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2011-10-19 22:24 ` [Bug c++/44906] g++ is giving error: parse error in template argument list manu at gcc dot gnu.org
@ 2021-08-04  6:20 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-04  6:20 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |NEW
   Last reconfirmed|2011-09-23 00:00:00         |2021-8-3

--- Comment #11 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
For the testcase in comment #8:

Ok, this is interesting as at first I thought this was fixed in GCC 11 but then
I looked to see what the different standards do as GCC 11's default is C++17.

With C++17 and C++20, we get:
<source>:8:34: error: use of 'this' in a constant expression
    8 |     void add(void) { addVecVals<&vec1>();  }
      |                                  ^~~~
<source>: In instantiation of 'void MISC<T>::add() [with T = int]':
<source>:13:10:   required from here
<source>:8:39: error: no matching function for call to
'MISC<int>::addVecVals<(&((MISC<int>*)this)->MISC<int>::vec1)>()'
    8 |     void add(void) { addVecVals<&vec1>();  }
      |                      ~~~~~~~~~~~~~~~~~^~
<source>:7:26: note: candidate: 'template<int* vc> void MISC<T>::addVecVals()
[with T* vc = vc; T = int]'
    7 |     template<T* vc> void addVecVals(){}
      |                          ^~~~~~~~~~
<source>:7:26: note:   template argument deduction/substitution failed:
<source>:8:34: error: '&((MISC<int>*)this)->MISC<int>::vec1' is not a valid
template argument of type 'int*' because '((MISC<int>*)this)->MISC<int>::vec1'
is not a variable
    8 |     void add(void) { addVecVals<&vec1>();  }
      |                                  ^~~~


But for C++98, C++11, C++14, we get:
<source>: In member function 'void MISC<T>::add()':
<source>:8:22: error: parse error in template argument list
    8 |     void add(void) { addVecVals<&vec1>();  }
      |                      ^~~~~~~~~~~~~~~~~

^ permalink raw reply	[flat|nested] 11+ 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; 11+ 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] 11+ 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; 11+ 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] 11+ 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; 11+ 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] 11+ 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; 11+ 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] 11+ 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; 11+ 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] 11+ 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; 11+ 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] 11+ messages in thread

end of thread, other threads:[~2021-08-04  6:20 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-44906-4@http.gcc.gnu.org/bugzilla/>
2011-09-23 12:55 ` [Bug c++/44906] g++ is giving error: parse error in template argument list while using a c++ code 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
2011-10-19 22:24 ` [Bug c++/44906] g++ is giving error: parse error in template argument list manu at gcc dot gnu.org
2021-08-04  6:20 ` pinskia at gcc dot gnu.org
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

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).