Bug 377140 - Signal methods no longer known as signals if signal method definition has been seen (e.g. with automoc)
Summary: Signal methods no longer known as signals if signal method definition has bee...
Status: RESOLVED FIXED
Alias: None
Product: clazy
Classification: Developer tools
Component: general (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Sergio Martins
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-03-03 03:23 UTC by Friedrich W. H. Kossebau
Modified: 2017-03-04 12:34 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
Diff to tests/incorrect-emit/main.cpp to reproduce the bug (929 bytes, patch)
2017-03-03 03:23 UTC, Friedrich W. H. Kossebau
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Friedrich W. H. Kossebau 2017-03-03 03:23:04 UTC
Created attachment 104332 [details]
Diff to tests/incorrect-emit/main.cpp to reproduce the bug

In Okteta I get some wrong "warning: Emit keyword being used with non-signal X::y" on emitting calls of some signals in inline methods of subclasses of the class with the signal.

It seems that happens when the method->getLocStart() in AccessSpecifierManager::qtAccessSpecifierType(...) does not point to the declaration of the signal method, but instead the definition (in the moc file). This happens e.g. on compiling automoc-generated bundle files, when the moc.cpp file for the class with the signal is included before the moc cpp files of the subclasses, whose inline methods (thus in the header) emit the signals:

OktetaKastenGui_automoc.cpp has e.g. the lines
#include "OktetaKastenGui_automoc.dir/moc_abstractbytear_XBUWMXYENN5IHJ.cpp"
#include "OktetaKastenGui_automoc.dir/moc_bytearraybase3_YVTH2B5RNQKBMM.cpp"

where the first line is the moc file for the class with the signal, and has
void Kasten::AbstractByteArrayStreamEncoder::settingsChanged()
{
    QMetaObject::activate(this, &staticMetaObject, 0, Q_NULLPTR);
}
Then the second pulls in the header of the subclass
#include "some/long/relative/path/bytearraybase32streamencoder.h"

That header has the inline definition of a method which emits settingsChanged():
inline void ByteArrayBase32StreamEncoder::setSettings( const Base32StreamEncoderSettings& settings )
{
    mSettings = settings;
    emit settingsChanged();
}

Which then gets the warning:
Emit keyword being used with non-signal Kasten::AbstractByteArrayStreamEncoder::settingsChanged [-Wclazy-incorrect-emit]

The reason for this misbehaviour can be seen by the output of
methodLoc.printToString(m_ci.getSourceManager())
in AccessSpecifierManager::qtAccessSpecifierType(...):
.../kasten/gui/OktetaKastenGui_automoc.dir/moc_abstractbytear_XBUWMXYENN5IHJ.cpp:124:1
so this now is not the signal method declaration, but the definition. Which screws the assumption in the method.

No clue about clang, also only typing this during sleep-interruption ;) thus just this report.

I could reduce the problem to the code attached as patch, as a new test case for tests/incorrect-emit. Not sure how much 377134 is related to this bug or if it only screws the bug simulation a little.
Comment 1 Sergio Martins 2017-03-04 01:31:26 UTC
Git commit 6d83b9398776eaa15505f496c5f7161a464c476e by Sergio Martins.
Committed on 04/03/2017 at 01:30.
Pushed by smartins into branch '1.1'.

incorrect-emit: Add failing unit-test for bug 377140

A  +30   -0    tests/incorrect-emit/bug377140.cpp     [License: UNKNOWN]  *
A  +0    -0    tests/incorrect-emit/bug377140.cpp.expected
M  +6    -2    tests/incorrect-emit/config.json

The files marked with a * at the end have a non valid license. Please read: http://techbase.kde.org/Policies/Licensing_Policy and use the headers which are listed at that page.


https://commits.kde.org/clazy/6d83b9398776eaa15505f496c5f7161a464c476e
Comment 2 Sergio Martins 2017-03-04 12:34:58 UTC
Git commit 53c68bc6888f18409f8e803fb5b9c59f9b1d96c9 by Sergio Martins.
Committed on 04/03/2017 at 12:32.
Pushed by smartins into branch '1.1'.

incorrect-emit: Fix two false positives

When we're comparing a method's source location to check if it's
affected by Q_SIGNAL we must use the first declaration of that method,
and not other declarations which can also be a a definition, and live
outside of the class
Related: bug 377134

M  +4    -0    src/AccessSpecifierManager.cpp
M  +2    -4    tests/incorrect-emit/config.json

https://commits.kde.org/clazy/53c68bc6888f18409f8e803fb5b9c59f9b1d96c9