Visual Studio 2019 - c++ is it possible to suppress function overloading

Hi,

is there a way to modify VS options to suppress function overloading, i.e. suppression of duplicate functions?

thanks in advance

cua
michael

No. Function overloading is a central feature of how C++ works as a language.

1 Like

Thank you,

i thought it would be impossible.

Now i got the confirmation.

Thanks again.

cu
michael

1 Like

Wih C++11, final specifier can be used to prevent any further overloading…

1 Like

You’ve confused overloading with overriding.
The former is an act of declaring more than one function with a given name but different parameters (or arguments, I never remember, which is which :wink: ).
The latter is used to implement polymorphic behaviour in conjunction with virtual.

1 Like

I don’t think so.
I use several Open source projects, where new modules came with different parameter lists. The amount of Parameters changed, so the debugger switched from three parameter call to two param function within one step. And without any error!

Cu

It sounds like you have symbol conflicts between libraries. You should get libraries to rename their types and symbols to be namespaced instead of trying to live in the global namespace with such generic names as Parameters.

1 Like

Thank you very much,

Btw. i Started programming c++ in the mid 80s on Siemens SX and MX and on DEC VAX computers. There i used to have Compilers which cried, when the Parameters did not Match. So it was easy to find the calls Not matching. Now If i have many modules it would be nice to have such a Compiler. With the present Project i found more than 10 functions where Parameters Not matching, but are called via debugger. A 3 parameter call to a function which has 2 Parameters or LEss, without Any existance of a called function with 3 parameters. This all Takes time.

Cu

I suspect that these compilers may have pre-dated C++ mangling setups (back when C++ was basically just a set of C macros). Now, C++ includes the argument list in the mangling, so different parameters make different symbols and no longer conflict.

If possible, a concrete example of what is causing your problem would help a lot here as I suspect a language barrier is confusing some of the description and understanding here.

1 Like

Hi Ben,

thanks again.

I don’t have the problem to get it solved.

I looked for a tool(or perhaps a compiler option) when run, which delivers a list of functions found, which have different amount of parameters, when called.
The work would be a bit easier.

So I have to do it manually, or I write my own function parser(it think, that would be the best way to go).

cu
michael

You mean a compiler warning like mentioned here?:

1 Like

This would be a First step, but within VS the Compiler does Not throw Any Warnings Like that.

I think, its the best way to get it by myself via own Parser.

To do this by hand ist crazy.

Cu
Michael

You could try with clang-tidy. VS2019 and later can include it. I only enabled some special rules, so no idea if you also can include this clang warning

1 Like

I think there’s a lot of talking past each other here. @michaelk1 can you please provide a snippet of code that shows what you would like to detect here?

1 Like

Give me a bit of time.

here we are:

just an example call function within the same module:

function header:

int my_data(char *comment, const char *data, int length)
{
.// nothing interresting here
.
.
}

called within the same module with:

	my_data("hello", 0, "\n", 5);

No compiler warning, debugger steps into “my_data”, 4 parameters given to function, but not beeing able to get the fourth parameter. No error.

Due to the fact, the open source project will be changed time by time. But i don’t know which parts are changed. If the producer of the project will change function “my_data” by changing the amount of arguments, it would be nice to have a list, which functions differ from the function calls, so i would be able to change the calls. you know without changing the calls, it will not be a question if the application crashes, but when.

And that will be not good for my stomach.

cua

p.s. the project is using mostly c constructs, as you can see

This code gives 1 or more syntax errors in any C++98 compiler (perhaps not in the 80’s).
There must be some more relevant code, if you really can compile this.
I can think of:

A. Macro defined like
#define my_data(a1,a2,a3,a4) my_data(a1,a3,a4)
Invisible for the debugger. Please look at the preprocessor output.

B. An additional overloaded function like

int my_data(char *comment, int IgnoredArg, const char *data, int length) {
  return my_data(comment, data, length);
}

exists.
If you compile in Debug mode without optimization you should recognize this by single stepping.

For any problem the preprocess output will help. You can easily search for all my_data definitions inside and find out in which headers they were defined.

Against wrongly/accidentially overloaded function, only coding conventions like using namespaces and/or classes helps.

1 Like

This code would give a warning (if not an error) in any of the compilers I have used.

1 Like

In the 80s there were warning/error messages.

At present I am using VS2019 and there I see no messages.
I think you are right, it is within the present context(prep directives etc.), because I cannot reproduce it within a clean project, just using the call and the function above. Here I get the messages I’d like to have.

I’ll try to find it out and let you know.

Thank you very much(to all of you)

cua
michael

Function-like macros that use the same convention as normal functions are a recipe for disaster and sometimes in a way no compiler can warn about. The thing will get replaced in a weird way when you least expect it. From your example I guess this is where the problem originates from.

1 Like

I agree with that.

In that case, i am expanding code which i have not written, this is getting me in this problematic situation.

Well, i think i write my own parser, finding these kind of calls(where the amount of parameters differs).

thank you.

cua
michael