"Incomplete \iffalse; all text was ignored after line x" with lstlisting

magyar.ldf actively prevents \initiate@active@char to write code to \AtBeginDocument which would add catcode changes to the aux-file.

This has the effect that when \subsection{+?} is written to the aux the code from listings interferes. (I didn't try to find out the details. magyar.ldf is imho a rather bad example of a language file, it patches all sorts of internal commands and is probably incompatible with a lot of other things).

You can try to get around the problem by adding the following to your preamble.

\usepackage[magyar]{babel}

\makeatletter
\expandafter\let\csname active@char\string?\endcsname\relax
\expandafter\let\csname active@char\string!\endcsname\relax
\expandafter\let\csname active@char\string:\endcsname\relax


\initiate@active@char{?}
\initiate@active@char{!}
\initiate@active@char{:}
\makeatother

Although I have to admit I do not really understand what causes this bug (I had the same behaviour as that described by the question), based on Ulrike Fischer's answer plus some other "hack" I already had around to fix hyphens in lstlistings, I found that the following code also fixes the issue. It has the advantage of being clearly defined in the scope of lstlisting, without affecting the rest of the document in any way:

\lstset{ % ... whatever was already there ...
        literate=% ... any other literates already there ...
                 {!}{!}1
                 {?}{?}1
                 {:}{:}1
}