Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8798005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:58:43+00:00 2026-06-13T23:58:43+00:00

template <typename T> void f() { return 0; // returning value from function returning

  • 0
template <typename T> void f() {
    return 0;  // returning value from function returning `void`
}

int main()
{
    // Not instantiating or calling any f<T>()
}

In comments to this answer, David asserts that a function template that contains a semantic error and is not instantiated causes a program to be ill-formed:

Whether the template is used or not does not matter, the program is ill-formed even with no instantiation but the compiler is not required to diagnose it.

Conversely, I am quite sure that SFINAE, as well as preventing type deduction and therefore instantiation of the function template per [C++11: 14.8.2/8], allows the program to remain well-formed. however I cannot find any text in this standard paragraph that explicitly says so.

Who is correct?


Wikipedia, which I shall not consider authoritative for this question, says about a slightly different case:

[..] SFINAE was introduced to avoid creating ill-formed programs when unrelated template declarations were visible [..]

(emphasis mine)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:58:45+00:00Added an answer on June 13, 2026 at 11:58 pm

    The program is ill-formed as per 14.6/8:

    If no valid specialization can be generated for a template definition, and that template is not instantiated, the template definition is ill-formed, no diagnostic required.

    That is whether you instantiate the template or not, the template definition is ill-formed as there is no possible instantiation that will succeed.

    Note that this is completely unrelated to SFINAE: Substitution Failure is not an Error is part of the substitution process, and never takes into account the contents of the template.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

template <typename T> void f(T&) {} template <typename T> void f(T&&) {} int main()
Consider this function template: template<typename T> unsigned long f(void *) { return 0;} Now,
#include <type_traits> template<class T> typename std::remove_reference<T>::type&& move(T&& v) { return v; } void main()
struct A { void f(int x) {} }; struct B { template<typename T> void
I have the following template declaration: template <typename T> void IterTable(int& rIdx, std::vector<double>& rVarVector,
I have a template method as follows:- template<typename T, int length> void ProcessArray(T array[length])
Imagine I have a template function like this: template<typename Iterator> void myfunc(Iterator a, typename
I'm trying to create a function: template <typename T> void doIt( T*& p )
I'am trying to do this work: template < typename T, T VALUE > void
template<int size> inline void* byteswap(void* __x); template<> inline void* byteswap<2>(void* __x) { return (*(uint16*)__x

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.