public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Sidney Marshall <sidneym@frontiernet.net>
To: gcc-help@gcc.gnu.org
Cc: sidneym@frontiernet.net
Subject: C++11 - Parameter pack question
Date: Sat, 16 Aug 2014 01:14:00 -0000	[thread overview]
Message-ID: <20140816011400.pXUHX0IFDF_n3xjg0DbvOT-XZz56z_PYJGdr9qAtOTo@z> (raw)

Hello,

The following code compiles and runs correctly but gives a warning:

----------------------------------------
#include<iostream>

using namespace std;

template<class T>
T sum(T value) {
   return value;
}

template<class T, class ... U>
auto sum(T value, U ... values) {
     return value + sum(values ...);
}

int main() {
   cout << sum(1, 2, 4.6) << endl;
   cout << sum(1, "abcde", 2) << endl;
}
--------------------------------------

$ g++ -std=c++11 pack.cpp
pack.cpp:11:31: warning: ‘sum’ function uses 
‘auto’ type specifier without trailing return type [enabled by default]
  auto sum(T value, U ... values) {

$ ./a.exe
7.6
de
-------------------------------------------

All of my attempts to use a trailing return type 
failed (and I believe should have failed according to the standard).

My two questions:

1. What possible user mistake is the warning worried about?

2. How can I write my code with better style so that there is no warning?

Thank you.

--Sidney Marshall

             reply	other threads:[~2014-08-16  1:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-16  1:14 Sidney Marshall [this message]
2014-08-16  1:14 Sidney Marshall
     [not found] <201408160114.s7G1EKDO087976@nef2.ens.fr>
2014-08-16  7:12 ` Marc Glisse
     [not found]   ` <alpine.DEB.2.11.1408160907210.1729@laptop-mg.saclay.inria. fr>
2014-08-17  2:28     ` Sidney Marshall
2014-08-17  2:28     ` Sidney Marshall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140816011400.pXUHX0IFDF_n3xjg0DbvOT-XZz56z_PYJGdr9qAtOTo@z \
    --to=sidneym@frontiernet.net \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).