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 6917593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:45:00+00:00 2026-05-27T09:45:00+00:00

Can a C++ user-defined literal operator ever be passed a null pointer? This is

  • 0

Can a C++ user-defined literal operator ever be passed a null pointer?

This is really happening with an experimental version of g++ (gcc version 4.7.0 20111114 (experimental) [trunk revision 181364] (Debian 20111114-1)) but I am unsure if this is a bug (90% sure) or some strange expected behavior.

Example program:

#include <iostream>
#include <stdexcept>
#include <string>

std::string operator "" _example (const char * text) {
  using std::cerr;
  using std::endl;
  cerr << "text (pointer) = " << static_cast<const void *>(text) << endl;
  if (!text) throw std::runtime_error("Is a null pointer really expected?");
  cerr << "text (string) = \"" << text << '"' << endl;
  return text;
}

int main() {
  2_example;
  1_example;
  0_example;
}

Output (probably a bug in gcc … but maybe not?!, hence the question):

text (pointer) = 0x8048d49
text (string) = "2"
text (pointer) = 0x8048d4b
text (string) = "1"
text (pointer) = 0
terminate called after throwing an instance of 'std::runtime_error'
  what():  Is a null pointer really expected?
Aborted

It’s not just “0_example”; it’s whenever the literal value is zero. For example, it still happens even when the literal is “0x0000_example”.

Is this a bug? Or some strange special-case when the literal’s value is zero?

  • 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-05-27T09:45:00+00:00Added an answer on May 27, 2026 at 9:45 am

    As Alf P. Steinbach assured me in a nice comment, this is a bug, not standard behavior (no big deal, since I was using a gcc snapshot).

    I went to file a gcc bug, but it looks like it’s already been filed and fixed upstream:

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

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

Sidebar

Related Questions

Why does C++ require that user-defined conversion operator can only be non-static member? Why
How can I get a user-defined function to re-evaluate itself based on changed data
How can I go about storing a vb.net user defined object in a sql
In C#, you can use the implicit keyword to define an implicit user-defined type
How can I set attribute to MVC2 user control defined in single file with
We know that TransactionScope class can use user-defined timeout value. But timeout exception is
If I have user defined exceptions in my code, I can't get Boost test
Is there a way I can query from within Vim information about user-defined vimscript
Can functions be used with user defined literals? If so, what shenanigans can be
I have a requirement whereby a user can specify a variable number of user-defined

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.