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

  • Home
  • SEARCH
  • 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 8271117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:45:51+00:00 2026-06-08T06:45:51+00:00

For this code struct test {}; test f() { return test(); } void print(test

  • 0

For this code

struct test {};
test f() { return test(); }
void print(test *x) {}
int main()
{
    print(&f());
    print(&test());
}

gcc-4.6 emits two “taking address of temporary [-fpermissive]” errors. This was introduced in 4.6, gcc-4.5 could compile it.

The reason is pretty clear and well documented. The problem is that it is a legacy code and, to compile, we have to make it work, thus, doing #pragmas around files and/or parts of code to compile them with -fpermissive. Let’s say, customers are adamant not to modify the existing code (i.e. the fact of calling print() with &f() or &test() cannot be changed, not source files in general). In other words, one way or another this will be compiled, the only choice is more or less pain.

So the question is – are there any possible workarounds to make it work without doing -fpermissive in lots of places? -W flags, C++ tricks, etc.

  • 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-08T06:45:52+00:00Added an answer on June 8, 2026 at 6:45 am

    What I meant is, the fact of calling print() with &f() or &test() cannot be changed.

    If you have control over the type itself, you can always overload the reference operator, operator&, and return this from it. It’s not a good thing to do in the general case, but it’s fairly safe considering that you’re returning the correct pointer of the correct type.

    If base classes are involved, then it becomes rather more complicated. You’ll need to use a virtual operator overload, and each class in the hierarchy will need to implement it separately.

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

Sidebar

Related Questions

I have this sample code: struct A { bool test() const { return false;
I am curious why this code works: typedef struct test_struct { int id; }
I have this code: struct A{}; template<class T = A> struct B { void
I have this code struct Student { char name[48]; float grade; int marks[10,5]; char
This is the code: struct comp { bool operator()(Reputation *one, Reputation *two) { if
I have this code: #include <iostream> #include <functional> struct A { int operator()(int i)
I have this code: void fill_array (unsigned int *iarray, char *string, int max) {
Code struct test { private real value; this(real value) { this.value = value; }
When I try to compile this code: struct BasicVertexProperties { Vect3Df position; }; struct
I have this code (C#): using System.Collections.Generic; namespace ConsoleApplication1 { public struct Thing {

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.