[LLVMbugs] [Bug 12859] New: False Positive Warning for 'conversion never used'.
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Thu May 17 01:04:15 PDT 2012
http://llvm.org/bugs/show_bug.cgi?id=12859
Bug #: 12859
Summary: False Positive Warning for 'conversion never used'.
Product: clang
Version: 3.0
Platform: PC
OS/Version: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: C++
AssignedTo: unassignedclangbugs at nondot.org
ReportedBy: turbobafalcon at hotmail.com
CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
Classification: Unclassified
I encountered code issuing an incorrect warning. The small test program below
reproduces the issue. The warning it gives is:
test.cpp:26:10: warning: conversion function converting 'MultiDerived' to its
base class 'BasePrivate' will never be used
virtual operator BasePrivate()
^
1 warning generated.
However, on executing it prints:
MultiDerived operator BasePrivate was invoked.
Therefore, the warning is untrue.
Apologies if this bug is invalid for some reason or is a duplicate, but it
would appear to me that the message should be improved to make clear the
unexpected behaviour that will result from code using this poor style, without
being misleading. E.g., in this particular case where the operator is virtual,
perhaps something like the following would be better (unless this is also
incorrect ...):
test.cpp:26:10: warning: conversion of 'MultiDerived' to its base class
'BasePrivate' will only use the provided conversion operator when accessed via
a less derived type.
virtual operator BasePrivate()
^
>>>>>>>>>>>>>>>>>>>>>>>>test.cpp contents<<<<<<<<<<<<<<<<<<<<<<<<<
#include <iostream>
#include <string>
using namespace std;
template<typename T>
struct BasePublic
{
virtual operator T() = 0;
};
struct BasePrivate
{
BasePrivate()
:
m_memberVar("Default value.")
{
}
string m_memberVar;
};
struct MultiDerived:
public BasePublic<BasePrivate>,
private BasePrivate
{
virtual operator BasePrivate()
{
m_memberVar = "MultiDerived operator BasePrivate was invoked.";
return (* this);
}
};
int main(int a_argc, char * a_argv[])
{
MultiDerived multiDerived;
BasePublic<BasePrivate> & basePublicRef = multiDerived;
BasePrivate testBPriv(basePublicRef);
cout << testBPriv.m_memberVar << endl;
}
--
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
More information about the llvm-bugs
mailing list